SynchronousProcessor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 12 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nexus;
6
7
use Nexus\Exceptions\TaskResultViolation;
8
use Psr\EventDispatcher\ListenerProviderInterface;
9
use Psr\EventDispatcher\StoppableTaskInterface;
10
use Psr\EventDispatcher\TaskInterface;
11
use Psr\EventDispatcher\TaskProcessorInterface;
12
13
class SynchronousProcessor implements TaskProcessorInterface
14
{
15
    private $listenerProvider;
16
17 3
    public function __construct(ListenerProviderInterface $listenerProvider)
18
    {
19 3
        $this->listenerProvider = $listenerProvider;
20 3
    }
21
22 3
    public function process(TaskInterface $task): TaskInterface
23
    {
24 3
        foreach ($this->listenerProvider->getListenersForEvent($task) as $listener) {
25 3
            $task = call_user_func($listener, $task);
26 3
            if (!is_object($task) || !($task instanceof TaskInterface)) {
27 1
                throw new TaskResultViolation();
28
            }
29 3
            if ($task instanceof StoppableTaskInterface && $task->isPropagationStopped()) {
30 3
                break;
31
            }
32
        }
33 2
        return $task;
34
    }
35
}
36