Completed
Push — master ( 67a92e...b03a00 )
by Grégoire
01:54
created

src/Event/DoctrineOptimizeListener.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NotificationBundle\Event;
15
16
use Symfony\Bridge\Doctrine\RegistryInterface;
17
18
/**
19
 * Doctrine context optimizer
20
 * Used to clear the doctrine context on each command iteration.
21
 * Do not use with doctrine backend, use DoctrineBackendOptimizeListener instead.
22
 *
23
 * @author Kevin Nedelec <[email protected]>
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): void
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