Completed
Branch conditions-refactoring (7efd7c)
by Romain
01:49
created

Validation::getParentField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/*
3
 * 2016 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 Formz project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Configuration\Form\Field\Validation;
15
16
use Romm\ConfigurationObject\Service\Items\Parents\ParentsTrait;
17
use Romm\ConfigurationObject\Traits\ConfigurationObject\ArrayConversionTrait;
18
use Romm\ConfigurationObject\Traits\ConfigurationObject\StoreArrayIndexTrait;
19
use Romm\Formz\Configuration\AbstractFormzConfiguration;
20
use Romm\Formz\Configuration\Form\Condition\Activation\ActivationInterface;
21
use Romm\Formz\Configuration\Form\Condition\Activation\EmptyActivation;
22
use Romm\Formz\Configuration\Form\Field\Field;
23
24
class Validation extends AbstractFormzConfiguration
25
{
26
27
    use StoreArrayIndexTrait;
28
    use ArrayConversionTrait;
29
    use ParentsTrait;
30
31
    /**
32
     * @var string
33
     * @validate NotEmpty
34
     * @validate Romm.Formz:Internal\ClassExists
35
     */
36
    protected $className;
37
38
    /**
39
     * @var string
40
     * @validate Number
41
     */
42
    protected $priority;
43
44
    /**
45
     * @var array
46
     */
47
    protected $options = [];
48
49
    /**
50
     * @var \ArrayObject<Romm\Formz\Configuration\Form\Field\Validation\Message>
51
     */
52
    protected $messages = [];
53
54
    /**
55
     * @var \Romm\Formz\Configuration\Form\Condition\Activation\ActivationResolver
56
     * @validate Romm.Formz:Internal\ConditionIsValid
57
     */
58
    protected $activation;
59
60
    /**
61
     * @var bool
62
     */
63
    protected $useAjax = false;
64
65
    /**
66
     * Constructor.
67
     */
68
    public function __construct()
69
    {
70
        $this->activation = EmptyActivation::get();
0 ignored issues
show
Documentation Bug introduced by
It seems like \Romm\Formz\Configuratio...\EmptyActivation::get() of type object<Romm\Formz\Config...vation\EmptyActivation> is incompatible with the declared type object<Romm\Formz\Config...ion\ActivationResolver> of property $activation.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getClassName()
77
    {
78
        return $this->className;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public function getPriority()
85
    {
86
        return $this->priority;
87
    }
88
89
    /**
90
     * @return array
91
     */
92
    public function getOptions()
93
    {
94
        return $this->options;
95
    }
96
97
    /**
98
     * @param string $optionName
99
     * @return null|mixed
100
     */
101
    public function getOption($optionName)
102
    {
103
        return (null !== $optionName && true === isset($this->options[$optionName]))
104
            ? $this->options[$optionName]
105
            : null;
106
    }
107
108
    /**
109
     * @return \Romm\Formz\Configuration\Form\Field\Validation\Message[]
110
     */
111
    public function getMessages()
112
    {
113
        return $this->messages;
114
    }
115
116
    /**
117
     * @return ActivationInterface
118
     */
119
    public function getActivation()
120
    {
121
        return $this->activation;
122
    }
123
124
    /**
125
     * @return bool
126
     */
127
    public function hasActivation()
128
    {
129
        return !($this->activation instanceof EmptyActivation);
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getValidationName()
136
    {
137
        return $this->getArrayIndex();
138
    }
139
140
    /**
141
     * @return bool
142
     */
143
    public function doesUseAjax()
144
    {
145
        return (bool) $this->useAjax;
146
    }
147
148
    /**
149
     * @return Field
150
     */
151
    public function getParentField()
152
    {
153
        return $this->getFirstParent(Field::class);
154
    }
155
}
156