Conditions | 1 |
Paths | 1 |
Total Lines | 80 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
154 | protected function createValidator(array $rules, array $data = []) |
||
155 | { |
||
156 | $config = new ValidatorConfig([ |
||
157 | /* |
||
158 | * Set of empty conditions which tells Validator what rules to be counted as "stop if empty", |
||
159 | * without such condition field validations will be skipped if value is empty. |
||
160 | */ |
||
161 | 'emptyConditions' => [ |
||
162 | "notEmpty", |
||
163 | "required", |
||
164 | "type::notEmpty", |
||
165 | "required::with", |
||
166 | "required::without", |
||
167 | "required::withAll", |
||
168 | "required::withoutAll", |
||
169 | "file::exists", |
||
170 | "file::uploaded", |
||
171 | "image::exists", |
||
172 | "image::uploaded", |
||
173 | "registry::anyValue", |
||
174 | /*{{empties}}*/ |
||
175 | ], |
||
176 | /* |
||
177 | * Checkers are resolved using container and provide ability to isolate some validation rules |
||
178 | * under common name and class. You can register new checkers at any moment without any |
||
179 | * performance issues. |
||
180 | */ |
||
181 | 'checkers' => [ |
||
182 | "registry" => RegistryChecker::class, |
||
183 | "entity" => EntityChecker::class, |
||
184 | "fields" => FieldsChecker::class, |
||
185 | /*{{checkers}}*/ |
||
186 | ], |
||
187 | /* |
||
188 | * Aliases are only used to simplify developer life. |
||
189 | */ |
||
190 | 'aliases' => [ |
||
191 | "notEmpty" => "type::notEmpty", |
||
192 | "required" => "type::notEmpty", |
||
193 | "datetime" => "type::datetime", |
||
194 | "timezone" => "type::timezone", |
||
195 | "bool" => "type::boolean", |
||
196 | "boolean" => "type::boolean", |
||
197 | "cardNumber" => "mixed::cardNumber", |
||
198 | "regexp" => "string::regexp", |
||
199 | "email" => "address::email", |
||
200 | "url" => "address::url", |
||
201 | "file" => "file::exists", |
||
202 | "uploaded" => "file::uploaded", |
||
203 | "filesize" => "file::size", |
||
204 | "image" => "image::valid", |
||
205 | "array" => "is_array", |
||
206 | "callable" => "is_callable", |
||
207 | "double" => "is_double", |
||
208 | "float" => "is_float", |
||
209 | "int" => "is_int", |
||
210 | "integer" => "is_integer", |
||
211 | "numeric" => "is_numeric", |
||
212 | "long" => "is_long", |
||
213 | "null" => "is_null", |
||
214 | "object" => "is_object", |
||
215 | "real" => "is_real", |
||
216 | "resource" => "is_resource", |
||
217 | "scalar" => "is_scalar", |
||
218 | "string" => "is_string", |
||
219 | "match" => "mixed::match", |
||
220 | /*{{aliases}}*/ |
||
221 | ] |
||
222 | ]); |
||
223 | |||
224 | $translator = \Mockery::mock(TranslatorInterface::class); |
||
225 | $translator->shouldReceive('resolveDomain')->andReturn('domain'); |
||
226 | $translator->shouldReceive('trans')->andReturn('error'); |
||
227 | |||
228 | $container = new Container(); |
||
229 | $container->bind(ContainerInterface::class, $container); |
||
230 | $container->bind(TranslatorInterface::class, $translator); |
||
231 | |||
232 | return new Validator($rules, $data, $config, $container); |
||
233 | } |
||
234 | } |
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..