Completed
Push — master ( 1fe708...6360f1 )
by Arnaud
16s queued 12s
created

CompositeDataHandler::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 4
c 1
b 1
f 0
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
cc 3
nc 3
nop 1
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\DataProvider\DataSourceHandler;
6
7
use LAG\AdminBundle\DataProvider\DataSourceInterface;
8
use LAG\AdminBundle\Exception\DataHandler\ClassNotSupportedException;
9
10
class CompositeDataHandler implements DataHandlerInterface
11
{
12
    /**
13
     * @var iterable<DataHandlerInterface>
14
     */
15
    private iterable $dataHandlers;
16
17
    public function __construct(iterable $dataHandlers)
18
    {
19
        $this->dataHandlers = $dataHandlers;
20
    }
21
22
    public function supports(DataSourceInterface $dataSource): bool
23
    {
24
        foreach ($this->dataHandlers as $dataHandler) {
25
            if ($dataHandler->supports($dataSource)) {
26
                return true;
27
            }
28
        }
29
30
        return false;
31
    }
32
33
    public function handle(DataSourceInterface $dataSource)
34
    {
35
        foreach ($this->dataHandlers as $dataHandler) {
36
            if ($dataHandler->supports($dataSource)) {
37
                return $dataHandler->handle($dataSource);
38
            }
39
        }
40
41
        throw new ClassNotSupportedException($dataSource);
42
    }
43
}
44