Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
10 / 10
JobListener
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
10 / 10
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 preFlush
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 preRemove
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
<?php
/*
 * This file is part of the Incipio package.
 *
 * (c) Théo FIDRY <theo.fidry@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace ApiBundle\EventListener\Doctrine;
use ApiBundle\Entity\Job;
use ApiBundle\Manager\NonPersistentEntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
/**
 * @author Théo FIDRY <theo.fidry@gmail.com>
 */
class JobListener
{
    /**
     * @var NonPersistentEntityManagerInterface
     */
    private $manager;
    /**
     * @param NonPersistentEntityManagerInterface $manager
     *
     * @throws \InvalidArgumentException If the manager does not supports the entity manipulated.
     */
    public function __construct(NonPersistentEntityManagerInterface $manager)
    {
        if (false === $manager->supports(Job::class)) {
            throw new \InvalidArgumentException(
                sprintf('The manager %s does not support %s objects.', get_class($manager), Job::class)
            );
        }
        $this->manager = $manager;
    }
    public function preFlush(Job $job, PreFlushEventArgs $args)
    {
        $this->manager->update($job);
    }
    public function preRemove(Job $job, LifecycleEventArgs $event)
    {
        $this->manager->remove($job);
    }
}