AddChildReader::getChildren()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 30
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Reader;
6
7
use Neimheadh\SonataAnnotationBundle\Annotation\AddChild;
8
use Neimheadh\SonataAnnotationBundle\Exception\MissingAnnotationArgumentException;
9
use ReflectionClass;
10
11
/**
12
 * AddChild annotation reader.
13
 *
14
 * @author Marko Kunic <[email protected]>
15
 * @author Mathieu Wambre <[email protected]>
16
 */
17
final class AddChildReader extends AbstractReader
18
{
19
20
    /**
21
     * Get admin children.
22
     *
23
     * @param ReflectionClass $class Entity class.
24
     *
25
     * @return array<string, string> Children model class => field list.
26
     */
27
    public function getChildren(ReflectionClass $class): array
28
    {
29
        $children = [];
30
31
        foreach (
32
            $this->getClassAnnotations(
33
                $class,
34
                AddChild::class
35
            ) as $annotation
36
        ) {
37
            if (!isset($annotation->class)) {
38
                throw new MissingAnnotationArgumentException(
39
                    $annotation,
40
                    'class',
41
                    $class
42
                );
43
            }
44
45
            if (!isset($annotation->field)) {
46
                throw new MissingAnnotationArgumentException(
47
                    $annotation,
48
                    'field',
49
                    $class
50
                );
51
            }
52
53
            $children[$annotation->class] = $annotation->field;
54
        }
55
56
        return $children;
57
    }
58
59
}
60