CompositeLocator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 22
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A locateCollection() 0 15 4
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