Completed
Pull Request — master (#540)
by
unknown
04:41
created

EventDispatcherFactory::__invoke()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4.1574

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 11
cts 14
cp 0.7856
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 6
nop 1
crap 4.1574
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace DoctrineORMModule;
21
22
use DoctrineORMModule\Exception\InvalidConfigurationException;
23
use Psr\Container\ContainerInterface;
24
use Symfony\Component\EventDispatcher\EventDispatcher;
25
26
/**
27
 * @license MIT
28
 * @link    www.doctrine-project.org
29
 * @author  Thomas Dutrion <[email protected]>
30
 */
31
final class EventDispatcherFactory
32
{
33
    /**
34
     * @param ContainerInterface $container
35
     *
36
     * @return EventDispatcher
37
     *
38
     * @throws \Psr\Container\ContainerExceptionInterface
39
     * @throws \Psr\Container\NotFoundExceptionInterface
40
     * @throws InvalidConfigurationException
41
     */
42 16
    public function __invoke(ContainerInterface $container)
43
    {
44 16
        $eventDispatcher = new EventDispatcher();
45
46 16
        $config = $container->get('config');
47 16
        $eventListenerConfig = isset($config['doctrine']['cli']['event_dispatcher']['listeners']) ?
48 16
            $config['doctrine']['cli']['event_dispatcher']['listeners'] :
49 16
            [];
50 16
        foreach ($eventListenerConfig as $event => $listener) {
51 16
            if (!$container->has($listener)) {
52
                throw new InvalidConfigurationException(
53
                    "configuration for doctrine.cli.event_dispatcher.listeners is invalid: Unable to find $listener in container."
54
                );
55
            }
56 16
            $eventDispatcher->addListener($event, $container->get($listener));
0 ignored issues
show
Documentation introduced by
$container->get($listener) is of type *, but the function expects a callable.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57 16
        }
58
59 16
        return $eventDispatcher;
60
    }
61
}
62