Conditions | 10 |
Paths | 7 |
Total Lines | 31 |
Code Lines | 17 |
Lines | 0 |
Ratio | 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 /** MicroCompareValidator */ |
||
26 | public function validate(IFormModel $model) |
||
27 | { |
||
28 | if (empty($this->params['attribute']) && empty($this->params['value'])) { |
||
29 | return false; |
||
30 | } |
||
31 | |||
32 | if (!$model->checkAttributeExists($this->params['attribute'])) { |
||
33 | throw new Exception('Attribute `' . $this->params['attribute'] . '` not found into ' . get_class($model)); |
||
34 | } |
||
35 | |||
36 | foreach ($this->elements AS $element) { |
||
37 | if (!$model->checkAttributeExists($element)) { |
||
38 | $this->errors[] = 'Parameter ' . $element . ' not defined in class ' . get_class($model); |
||
39 | |||
40 | return false; |
||
41 | } |
||
42 | |||
43 | $elementValue = $model->$element; |
||
44 | if (!empty($this->params['value']) && ($this->params['value'] !== $elementValue)) { |
||
45 | $this->errors[] = 'Parameter ' . $element . ' not equal ' . $this->params['value']; |
||
46 | |||
47 | return false; |
||
48 | } elseif (!empty($this->params['attribute']) && ($model->{$this->params['attribute']} !== $elementValue)) { |
||
49 | $this->errors[] = 'Parameter ' . $element . ' not equal ' . $model->{$this->params['attribute']}; |
||
50 | |||
51 | return false; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | return true; |
||
56 | } |
||
57 | |||
74 |