Passed
Push — develop ( 355f63...51016a )
by Mathieu
02:23
created

AddChild::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Annotation\Sonata;
6
7
use Attribute;
8
use Neimheadh\SonataAnnotationBundle\Annotation\AbstractAnnotation;
9
use ReflectionException;
10
11
/**
12
 * Add child annotation.
13
 *
14
 * Add child admin to current admin class or admin annotated model.
15
 *
16
 * @Annotation
17
 * @Target("CLASS")
18
 *
19
 * @author Marko Kunic <[email protected]>
20
 * @author Mathieu Wambre <[email protected]>
21
 */
22
#[Attribute(Attribute::TARGET_CLASS)]
23
final class AddChild extends AbstractAnnotation
24
{
25
26
    /**
27
     * Child model class.
28
     *
29
     * @var string|null
30
     */
31
    public ?string $class = null;
32
33
    /**
34
     * Reverse field.
35
     *
36
     * @var string|null
37
     */
38
    public ?string $field = null;
39
40
    /**
41
     * @param string|array|null $class Model class or annotation parameters.
42
     * @param string|null       $field Reverse field.
43
     *
44
     * @throws ReflectionException
45
     */
46
    public function __construct(
47
        $class = null,
48
        ?string $field = null
49
    ) {
50
        $this->field = $field;
51
52
        if (is_array($class)) {
53
            $this->initAnnotation($class);
54
        } else {
55
            $this->class = $class;
56
        }
57
    }
58
59
}
60