SymfonyEventAdapter::getInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: thalesmartins
5
 * Date: 11/12/2018
6
 * Time: 13:36
7
 */
8
9
namespace Saci\Console\Infrastructure\Application;
10
11
12
use Saci\Console\Application\Events\EventManagerAdpter;
13
use Saci\Console\Domain\Events\Event;
14
use Saci\Console\Domain\Events\Subscriber;
15
use Symfony\Component\EventDispatcher\EventDispatcher;
16
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17
18
class SymfonyEventAdapter implements EventManagerAdpter
19
{
20
21
    private static $instance;
22
    /** @var EventDispatcher */
23
    private $eventDispatcher;
24
25 1
    private function __construct()
26
    {
27 1
        $this->eventDispatcher = new EventDispatcher();
28 1
    }
29
30 2
    public static function getInstance()
31
    {
32 2
        if (self::$instance === null) {
33 1
            self::$instance = new self();
34
        }
35
36 2
        return self::$instance;
37
    }
38
39 2
    public function addSubscriber(Subscriber $subscriber)
40
    {
41
        /** @var EventSubscriberInterface $subs */
42 2
        $subs = $subscriber;
43 2
        $this->eventDispatcher->addSubscriber($subs);
44 2
    }
45
46 2
    public function publish(Event $event)
47
    {
48
        /** @var \Symfony\Component\EventDispatcher\Event $event */
49 2
        $evt = $event;
50 2
        $this->eventDispatcher->dispatch($event->getName(), $evt);
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Symfony\Component\EventDispatcher\Event. It seems like you code against a sub-type of Symfony\Component\EventDispatcher\Event such as Saci\Console\Infrastruct...Events\ModuleWasCreated or Saci\Console\Infrastruct...vents\CommandWasCreated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $this->eventDispatcher->dispatch($event->/** @scrutinizer ignore-call */ getName(), $evt);
Loading history...
51 2
    }
52
53
    private function __clone()
54
    {
55
    }
56
}