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

AbstractField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
dl 0
loc 57
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A getSettings() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Annotation;
6
7
use ReflectionException;
8
9
/**
10
 * Field annotations main class.
11
 *
12
 * @author Marko Kunic <[email protected]>
13
 * @author Mathieu Wambre <[email protected]>
14
 */
15
abstract class AbstractField extends AbstractAnnotation
16
{
17
18
    /**
19
     * Field type.
20
     *
21
     * @var string|null
22
     */
23
    public ?string $type = null;
24
25
    /**
26
     * Field description options.
27
     *
28
     * @var array
29
     */
30
    public array $fieldDescriptionOptions = [];
31
32
    /**
33
     * Field position.
34
     *
35
     * @var int|null
36
     */
37
    public ?int $position = null;
38
39
    /**
40
     * @param string|array|null $type                    Type or annotation
41
     *                                                   parameters.
42
     * @param array             $fieldDescriptionOptions Description options.
43
     * @param int|null          $position                Position.
44
     *
45
     * @throws ReflectionException
46
     */
47
    public function __construct(
48
        $type = null,
49
        array $fieldDescriptionOptions = [],
50
        ?int $position = null
51
    ) {
52
        $this->fieldDescriptionOptions = $fieldDescriptionOptions;
53
        $this->position = $position;
54
55
        if (is_array($type)) {
56
            $this->initAnnotation($type);
57
        } else {
58
            $this->type = $type;
59
        }
60
    }
61
62
    /**
63
     * Get field settings.
64
     *
65
     * @return array
66
     */
67
    public function getSettings(): array
68
    {
69
        return [
70
            $this->type ?? null,
71
            $this->fieldDescriptionOptions,
72
        ];
73
    }
74
75
}
76