1 | <?php |
||
13 | class ValidationField { |
||
14 | /** |
||
15 | * @var array|Schema |
||
16 | */ |
||
17 | private $field; |
||
18 | |||
19 | /** |
||
20 | * @var Validation |
||
21 | */ |
||
22 | private $validation; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | private $name; |
||
28 | |||
29 | /** |
||
30 | * Construct a new {@link ValidationField} object. |
||
31 | * |
||
32 | * @param Validation $validation The validation object that contains errors. |
||
33 | * @param array|Schema $field The field definition. |
||
34 | * @param string $name The path to the field. |
||
35 | */ |
||
36 | 90 | public function __construct(Validation $validation, $field, $name) { |
|
41 | |||
42 | /** |
||
43 | * Add a validation error. |
||
44 | * |
||
45 | * @param string $error The message code. |
||
46 | * @param int|array $options An array of additional information to add to the error entry or a numeric error code. |
||
47 | * @return $this |
||
48 | * @see Validation::addError() |
||
49 | */ |
||
50 | 24 | public function addError($error, $options = []) { |
|
54 | |||
55 | /** |
||
56 | * Add an invalid type error. |
||
57 | * |
||
58 | * @param string $type The type that was checked. |
||
59 | * @return $this |
||
60 | */ |
||
61 | 35 | public function addTypeError($type = '') { |
|
76 | |||
77 | /** |
||
78 | * Check whether or not this field is has errors. |
||
79 | * |
||
80 | * @return bool Returns true if the field has no errors, false otherwise. |
||
81 | */ |
||
82 | public function isValid() { |
||
85 | |||
86 | /** |
||
87 | * Merge a validation object to this one. |
||
88 | * |
||
89 | * @param Validation $validation The validation object to merge. |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function merge(Validation $validation) { |
||
96 | |||
97 | /** |
||
98 | * Get the field. |
||
99 | * |
||
100 | * @return array|Schema Returns the field. |
||
101 | */ |
||
102 | 90 | public function getField() { |
|
105 | |||
106 | /** |
||
107 | * Set the field. |
||
108 | * |
||
109 | * This method is only meant to be called from within the schema class. |
||
110 | * |
||
111 | * @param array|Schema $field The new field. |
||
112 | * @return $this |
||
113 | */ |
||
114 | 72 | public function setField($field) { |
|
118 | |||
119 | /** |
||
120 | * Get the validation. |
||
121 | * |
||
122 | * @return Validation Returns the validation. |
||
123 | */ |
||
124 | 90 | public function getValidation() { |
|
127 | |||
128 | /** |
||
129 | * Get the name. |
||
130 | * |
||
131 | * @return string Returns the name. |
||
132 | */ |
||
133 | 90 | public function getName() { |
|
136 | |||
137 | /** |
||
138 | * Set the name. |
||
139 | * |
||
140 | * This method is only meant to be called from within the schema class. |
||
141 | * |
||
142 | * @param string $name The new name. |
||
143 | * @return $this |
||
144 | */ |
||
145 | 72 | public function setName($name) { |
|
149 | |||
150 | /** |
||
151 | * Get the field type. |
||
152 | * |
||
153 | * @return string|null Returns a type string or null if there isn't one. |
||
154 | */ |
||
155 | 90 | public function getType() { |
|
158 | |||
159 | /** |
||
160 | * Get a value fom the field. |
||
161 | * |
||
162 | * @param string $key The key to look at. |
||
163 | * @param mixed $default The default to return if the key isn't found. |
||
164 | * @return mixed Returns a value or the default. |
||
165 | */ |
||
166 | 89 | public function val($key, $default = null) { |
|
169 | } |
||
170 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.