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

DoctrineOptimizeListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 4
c 4
b 1
f 1
lcom 1
cbo 0
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A iterate() 0 10 3
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