Passed
Pull Request — master (#259)
by Arnaud
08:22
created

CompositeDataHandler::supports()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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