Completed
Push — 2.x-dev-kit ( 8d77e1 )
by
unknown
28:22 queued 25:50
created

DoctrineOptimizeListener::iterate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata project.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NotificationBundle\Event;
13
14
use Symfony\Bridge\Doctrine\RegistryInterface;
15
16
/**
17
 * Doctrine context optimizer
18
 * Used to clear the doctrine context on each command iteration.
19
 * Do not use with doctrine backend, use DoctrineBackendOptimizeListener instead.
20
 *
21
 * @author Kevin Nedelec <[email protected]>
22
 *
23
 * Class DoctrineOptimizeListener
24
 */
25
class DoctrineOptimizeListener implements IterationListener
26
{
27
    /**
28
     * @var Registry
29
     */
30
    protected $doctrine;
31
32
    /**
33
     * @param RegistryInterface $doctrine
34
     */
35
    public function __construct(RegistryInterface $doctrine)
36
    {
37
        $this->doctrine = $doctrine;
0 ignored issues
show
Documentation Bug introduced by
It seems like $doctrine of type object<Symfony\Bridge\Doctrine\RegistryInterface> is incompatible with the declared type object<Sonata\NotificationBundle\Event\Registry> of property $doctrine.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function iterate(IterateEvent $event)
44
    {
45
        foreach ($this->doctrine->getManagers() as $name => $manager) {
46
            if (!$manager->isOpen()) {
47
                throw new \RuntimeException(sprintf('The doctrine manager: %s is closed', $name));
48
            }
49
50
            $manager->getUnitOfWork()->clear();
51
        }
52
    }
53
}
54