SymfonyBridge::dispatch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
/**
3
 * This file is part of phpab/phpab. (https://github.com/phpab/phpab)
4
 *
5
 * @link https://github.com/phpab/phpab for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab/master/LICENSE.md MIT
8
 */
9
10
namespace PhpAb\Event;
11
12
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
13
14
/**
15
 * An event dispatcher that acts as a bridge between phpab and Symfony.
16
 *
17
 * @package PhpAb
18
 */
19
class SymfonyBridge implements DispatcherInterface
20
{
21
    /**
22
     * The event dispatcher used to invoke events.
23
     *
24
     * @var EventDispatcherInterface
25
     */
26
    private $eventDispatcher;
27
28
    /**
29
     * Initializes a new instance of this class.
30
     *
31
     * @param EventDispatcherInterface $eventDispatcher The Symfony EventDispatcher
32
     */
33 4
    public function __construct(EventDispatcherInterface $eventDispatcher)
34
    {
35 4
        $this->eventDispatcher = $eventDispatcher;
36 4
    }
37
38
    /**
39
     * {@inheritDoc}
40
     *
41
     * @param string $event The name of the Event which should be dispatched
42
     * @param array $options The options that should get passed to the callback
43
     */
44 4
    public function dispatch($event, $options)
45
    {
46 4
        $listeners = $this->eventDispatcher->getListeners($event);
47
48 4
        foreach ($listeners as $listener) {
49 3
            call_user_func($listener, $options);
50 4
        }
51 4
    }
52
53
    /**
54
     * Gets the original EventDispatcher
55
     *
56
     * @return EventDispatcherInterface
57
     */
58 3
    public function getOriginal()
59
    {
60 3
        return $this->eventDispatcher;
61
    }
62
}
63