Completed
Push — unit-tests-validation ( 34c29c...a12b55 )
by Romain
02:46
created

Validation::setActivation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/*
3
 * 2017 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\ActivationUsageInterface;
22
use Romm\Formz\Configuration\Form\Condition\Activation\EmptyActivation;
23
use Romm\Formz\Configuration\Form\Field\Field;
24
25
class Validation extends AbstractFormzConfiguration implements ActivationUsageInterface
26
{
27
    use StoreArrayIndexTrait;
28
    use ArrayConversionTrait;
29
    use ParentsTrait;
30
31
    /**
32
     * @var string
33
     * @validate NotEmpty
34
     * @validate Romm.ConfigurationObject:ClassImplements(interface=TYPO3\CMS\Extbase\Validation\Validator\ValidatorInterface)
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
     * Name of the validation. By default, it is the key of this validation in
67
     * the array containing all validations for the parent field.
68
     *
69
     * @var string
70
     */
71
    private $validationName;
72
73
    /**
74
     * Constructor.
75
     */
76
    public function __construct()
77
    {
78
        $this->activation = EmptyActivation::get();
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getClassName()
85
    {
86
        return $this->className;
87
    }
88
89
    /**
90
     * @param string $className
91
     */
92
    public function setClassName($className)
93
    {
94
        $this->className = $className;
95
    }
96
97
    /**
98
     * @return int
99
     */
100
    public function getPriority()
101
    {
102
        return $this->priority;
103
    }
104
105
    /**
106
     * @return array
107
     */
108
    public function getOptions()
109
    {
110
        return $this->options;
111
    }
112
113
    /**
114
     * @param string $optionName
115
     * @return null|mixed
116
     */
117
    public function getOption($optionName)
118
    {
119
        return (null !== $optionName && true === isset($this->options[$optionName]))
120
            ? $this->options[$optionName]
121
            : null;
122
    }
123
124
    /**
125
     * @return Message[]
126
     */
127
    public function getMessages()
128
    {
129
        return $this->messages;
130
    }
131
132
    /**
133
     * @param Message[] $messages
134
     */
135
    public function setMessages(array $messages)
136
    {
137
        $this->messages = $messages;
138
    }
139
140
    /**
141
     * @return ActivationInterface
142
     */
143
    public function getActivation()
144
    {
145
        return $this->activation;
146
    }
147
148
    /**
149
     * @return bool
150
     */
151
    public function hasActivation()
152
    {
153
        return !($this->activation instanceof EmptyActivation);
154
    }
155
156
    /**
157
     * @param ActivationInterface $activation
158
     */
159
    public function setActivation(ActivationInterface $activation)
160
    {
161
        $activation->setRootObject($this);
162
163
        $this->activation = $activation;
0 ignored issues
show
Documentation Bug introduced by
$activation is of type object<Romm\Formz\Config...on\ActivationInterface>, but the property $activation was declared to be of type object<Romm\Formz\Config...ion\ActivationResolver>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
164
    }
165
166
    /**
167
     * @return string
168
     */
169
    public function getValidationName()
170
    {
171
        if (null === $this->validationName) {
172
            $this->validationName = $this->getArrayIndex();
173
        }
174
175
        return $this->validationName;
176
    }
177
178
    /**
179
     * @return bool
180
     */
181
    public function doesUseAjax()
182
    {
183
        return (bool)$this->useAjax;
184
    }
185
186
    /**
187
     * @param bool $flag
188
     */
189
    public function activateAjaxUsage($flag = true)
190
    {
191
        $this->useAjax = (bool)$flag;
192
    }
193
194
    /**
195
     * @param string $validationName
196
     */
197
    public function setValidationName($validationName)
198
    {
199
        $this->validationName = $validationName;
200
    }
201
202
    /**
203
     * @return Field
204
     */
205
    public function getParentField()
206
    {
207
        return $this->getFirstParent(Field::class);
208
    }
209
}
210