CompositeEventHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 3
A __construct() 0 3 1
A supports() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusPaginationPlugin\EventHandler;
6
7
use Setono\SyliusPaginationPlugin\Exception\NoSupportedHandlerException;
8
use Setono\SyliusPaginationPlugin\ParameterBag\PaginationParameterBag;
9
use Symfony\Component\EventDispatcher\Event;
10
11
final class CompositeEventHandler implements EventHandlerInterface
12
{
13
    /**
14
     * @var EventHandlerInterface[]
15
     */
16
    private $eventHandlers;
17
18
    public function __construct(EventHandlerInterface ...$eventHandlers)
19
    {
20
        $this->eventHandlers = $eventHandlers;
21
    }
22
23
    public function supports(Event $event): bool
24
    {
25
        foreach ($this->eventHandlers as $eventHandler) {
26
            if ($eventHandler->supports($event)) {
27
                return true;
28
            }
29
        }
30
31
        return false;
32
    }
33
34
    public function handle(Event $event): PaginationParameterBag
35
    {
36
        foreach ($this->eventHandlers as $eventHandler) {
37
            if ($eventHandler->supports($event)) {
38
                return $eventHandler->handle($event);
39
            }
40
        }
41
42
        throw new NoSupportedHandlerException($event);
43
    }
44
}
45