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

FormField   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 62
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getSettings() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Neimheadh\SonataAnnotationBundle\Annotation\Sonata;
6
7
use Attribute;
8
use Neimheadh\SonataAnnotationBundle\Annotation\AbstractField;
9
use Neimheadh\SonataAnnotationBundle\Annotation\ActionAnnotationInterface;
10
use Neimheadh\SonataAnnotationBundle\Annotation\PositionAnnotationInterface;
11
use ReflectionException;
12
13
/**
14
 * Form field annotation.
15
 *
16
 * Allows you to configure form field for the annotated property.
17
 *
18
 * @Annotation
19
 * @Target("PROPERTY")
20
 *
21
 * @author Marko Kunic <[email protected]>
22
 * @author Mathieu Wambre <[email protected]>
23
 */
24
#[Attribute(Attribute::TARGET_PROPERTY)]
25
final class FormField extends AbstractField implements
26
    ActionAnnotationInterface,
27
    PositionAnnotationInterface
28
{
29
30
    /**
31
     * Create action name.
32
     */
33
    public const ACTION_CREATE = 'create';
34
35
    /**
36
     * Edit action name.
37
     */
38
    public const ACTION_EDIT = 'edit';
39
40
    /**
41
     * Action name.
42
     *
43
     * @var string|null
44
     */
45
    public ?string $action = null;
46
47
    /**
48
     * Field options.
49
     *
50
     * @var array
51
     */
52
    public array $options = [];
53
54
    /**
55
     * {@inheritDoc}
56
     *
57
     * @param string|null $action  Action name.
58
     * @param array       $options Field options.
59
     *
60
     * @throws ReflectionException
61
     */
62
    public function __construct(
63
        $type = null,
64
        array $fieldDescriptionOptions = [],
65
        ?int $position = null,
66
        ?string $action = null,
67
        array $options = []
68
    ) {
69
        $this->action = $action;
70
        $this->options = $options;
71
72
        parent::__construct($type, $fieldDescriptionOptions, $position);
73
    }
74
75
    /**
76
     * Get field form settings.
77
     *
78
     * @return array
79
     */
80
    public function getSettings(): array
81
    {
82
        return [
83
            $this->type,
84
            $this->options,
85
            $this->fieldDescriptionOptions,
86
        ];
87
    }
88
89
}
90