CompositeEventHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
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