Passed
Pull Request — 1.x (#9)
by Marko
02:32
created

AddChild   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getClass() 0 10 2
A getField() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\Annotation;
6
7
/**
8
 * @Annotation
9
 * @Target("CLASS")
10
 *
11
 * @author Marko Kunic <[email protected]>
12
 */
13
final class AddChild implements AnnotationInterface
14
{
15
    /**
16
     * @var string
17
     */
18
    public $class;
19
20
    /**
21
     * @var string
22
     */
23
    public $field;
24
25
    public function getClass(): string
26
    {
27
        if ($this->class) {
28
            return $this->class;
29
        }
30
31
        throw new \InvalidArgumentException(
32
            sprintf(
33
                'Argument "class" is mandatory in "%s" annotation.',
34
                self::class
35
            )
36
        );
37
    }
38
39
    public function getField(): string
40
    {
41
        if ($this->field) {
42
            return $this->field;
43
        }
44
45
        throw new \InvalidArgumentException(
46
            sprintf(
47
                'Argument "field" is mandatory in "%s" annotation.',
48
                self::class
49
            )
50
        );
51
    }
52
}
53