Conditions | 12 |
Paths | 8 |
Total Lines | 34 |
Code Lines | 19 |
Lines | 17 |
Ratio | 50 % |
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 /** MicroFileValidator */ |
||
24 | public function validate(IFormModel $model) |
||
25 | { |
||
26 | foreach ($this->elements AS $element) { |
||
27 | if (!$model->checkAttributeExists($element)) { |
||
28 | $files = $this->container->request->getFiles(); |
||
|
|||
29 | if (!empty($this->params['maxFiles']) && (count($files->files) > $this->params['maxFiles'])) { |
||
30 | $this->errors[] = 'Too many files in parameter ' . $element; |
||
31 | |||
32 | return false; |
||
33 | } |
||
34 | foreach ($files->files AS $fContext) { |
||
35 | View Code Duplication | if (!empty($this->params['types']) && (strpos($this->params['types'], |
|
36 | $fContext['type']) === false) |
||
37 | ) { |
||
38 | $this->errors[] = 'File ' . $fContext['name'] . ' not allowed type'; |
||
39 | |||
40 | return false; |
||
41 | } |
||
42 | View Code Duplication | if (!empty($this->params['minSize']) && ($fContext['size'] < $this->params['minSize'])) { |
|
43 | $this->errors[] = 'File ' . $fContext['name'] . ' too small size'; |
||
44 | |||
45 | return false; |
||
46 | } |
||
47 | View Code Duplication | if (!empty($this->params['maxSize']) && ($fContext['type'] > $this->params['maxSize'])) { |
|
48 | $this->errors[] = 'File ' . $fContext['name'] . ' too many size'; |
||
49 | |||
50 | return false; |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 | } |
||
55 | |||
56 | return true; |
||
57 | } |
||
58 | |||
67 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: