Passed
Pull Request — 1.x (#35)
by Marko
05:54
created

FormField::getPosition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace KunicMarko\SonataAnnotationBundle\Annotation;
6
7
/**
8
 * @Annotation
9
 * @Target("PROPERTY")
10
 *
11
 * @author Marko Kunic <[email protected]>
12
 */
13
final class FormField extends AbstractField
14
{
15
    public const ACTION_CREATE = 'create';
16
    public const ACTION_EDIT = 'edit';
17
18
    /**
19
     * @var string
20
     */
21
    public $action;
22
23
    /**
24
     * @var array
25
     */
26
    public $options = [];
27
28
    /**
29
     * @var integer
30
     */
31
    public $position;
32
33
    /**
34
     * @var string
35
     */
36
    public $group;
37
38
    /**
39
     * @var string
40
     */
41
    public $tab;
42
43
    public function getSettings(): array
44
    {
45
        return [
46
            $this->type,
47
            $this->options,
48
            $this->fieldDescriptionOptions
49
        ];
50
    }
51
52
    public function hasGroup(): bool
53
    {
54
        return $this->group !== null;
55
    }
56
57
    public function hasTab(): bool
58
    {
59
        return $this->tab !== null;
60
    }
61
62
    public function getGroup(): ?string
63
    {
64
        if ($this->tab && $this->group) {
65
            throw new \InvalidArgumentException('You can set either group or tab, not both.');
66
        }
67
68
        return $this->group !== "" ? $this->group : null;
69
    }
70
71
    public function getTab(): ?string
72
    {
73
        if ($this->tab && $this->group) {
74
            throw new \InvalidArgumentException('You can set either group or tab, not both.');
75
        }
76
77
        return $this->tab !== "" ? $this->tab : null;
78
    }
79
}
80