Passed
Pull Request — master (#417)
by Alejandro
06:44
created

EventListenerTask   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 21
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A run() 0 3 1
A toString() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\EventDispatcher\Listener;
5
6
use Psr\Container\ContainerInterface;
7
use Shlinkio\Shlink\EventDispatcher\Async\TaskInterface;
8
9
use function get_class;
10
use function sprintf;
11
12
class EventListenerTask implements TaskInterface
13
{
14
    /** @var string */
15
    private $listenerName;
16
    /** @var object */
17
    private $event;
18
19 3
    public function __construct(string $listenerName, object $event)
20
    {
21 3
        $this->listenerName = $listenerName;
22 3
        $this->event = $event;
23
    }
24
25 1
    public function run(ContainerInterface $container): void
26
    {
27 1
        ($container->get($this->listenerName))($this->event);
28
    }
29
30 1
    public function toString(): string
31
    {
32 1
        return sprintf('Listener -> "%s", Event -> "%s"', $this->listenerName, get_class($this->event));
33
    }
34
}
35