CompositeLocator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Metadata\Locator;
6
7
use LAG\AdminBundle\Exception\Exception;
8
use LAG\AdminBundle\Metadata\AdminResource;
9
10
class CompositeLocator implements MetadataLocatorInterface
11
{
12
    public function __construct(
13
        private iterable $locators,
14
    ) {
15
    }
16
17
    public function locateCollection(string $resourceDirectory): array
18
    {
19
        $resources = [];
20
21
        /** @var MetadataLocatorInterface $locator */
22
        foreach ($this->locators as $locator) {
23
            foreach ($locator->locateCollection($resourceDirectory) as $resource) {
24
                if (!$resource instanceof AdminResource) {
25
                    throw new Exception(sprintf('The locator "%s" returns an instance of "%s", expected an instance of "%s"', \get_class($locator), \get_class($resource), AdminResource::class));
26
                }
27
                $resources[] = $resource;
28
            }
29
        }
30
31
        return $resources;
32
    }
33
}
34