Completed
Push — master ( de84eb...d1f862 )
by Jaap
18s queued 11s
created

Dispatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of phpDocumentor.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @link http://phpdoc.org
12
 */
13
14
namespace phpDocumentor\Event;
15
16
use Symfony\Component\EventDispatcher\EventDispatcher;
17
18
/**
19
 * Event Dispatching class.
20
 *
21
 * This class provides a bridge to the Symfony2 EventDispatcher.
22
 * At current this is provided by inheritance but future iterations should
23
 * solve this by making it an adapter pattern.
24
 *
25
 * The class is implemented as (mockable) Singleton as this was the best
26
 * solution to make the functionality available in every class of the project.
27
 */
28
class Dispatcher extends EventDispatcher
29
{
30
    /** @var Dispatcher[] Keep track of an array of instances. */
31
    protected static $instances = [];
32
33
    /**
34
     * Returns a named instance of the Event Dispatcher.
35
     */
36 5
    public static function getInstance(string $name = 'default') : self
37
    {
38 5
        if (!isset(self::$instances[$name])) {
39 2
            self::setInstance($name, new self());
0 ignored issues
show
Documentation introduced by
new self() is of type object<phpDocumentor\Event\Dispatcher>, but the function expects a object<self>.

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...
40
        }
41
42 5
        return self::$instances[$name];
43
    }
44
45
    /**
46
     * Sets a names instance of the Event Dispatcher.
47
     */
48 1
    public static function setInstance(string $name, self $instance) : void
49
    {
50 1
        self::$instances[$name] = $instance;
51 1
    }
52
}
53