AttributeLocator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 19
c 1
b 0
f 1
dl 0
loc 33
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A locateCollection() 0 31 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Metadata\Locator;
6
7
use LAG\AdminBundle\Metadata\AdminResource;
8
use LAG\AdminBundle\Metadata\AttributesHelper;
9
10
use function Symfony\Component\String\u;
11
12
class AttributeLocator implements MetadataLocatorInterface
13
{
14
    public function locateCollection(string $resourceDirectory): iterable
15
    {
16
        $classes = AttributesHelper::getReflectionClassesFromDirectories($resourceDirectory);
17
        $resources = [];
18
19
        foreach ($classes as $reflectionClass) {
20
            $attributes = $reflectionClass->getAttributes(AdminResource::class);
21
22
            foreach ($attributes as $attribute) {
23
                /** @var AdminResource $resource */
24
                $resource = $attribute->newInstance();
25
                $resource = $resource->withDataClass($reflectionClass->getName());
26
27
                if (!$resource->getName()) {
28
                    $resource = $resource->withName(
29
                        u($reflectionClass->getName())
30
                            ->afterLast('\\')
31
                            ->snake()
32
                            ->lower()
33
                            ->toString()
34
                    );
35
                }
36
37
                if (!$resource->getDataClass()) {
38
                    $resource = $resource->withDataClass($reflectionClass->getName());
39
                }
40
                $resources[] = $resource;
41
            }
42
        }
43
44
        return $resources;
45
    }
46
}
47