Conditions | 10 |
Paths | 16 |
Total Lines | 28 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 20 |
CRAP Score | 10 |
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 defined('SYSPATH') OR die('No direct script access.'); |
||
21 | 16 | public function validate(Jam_Validated $model, $attribute, $value) |
|
22 | { |
||
23 | 16 | $count = count($value); |
|
24 | 16 | $params = (array) $this; |
|
|
|||
25 | |||
26 | 16 | if ($this->minimum !== NULL AND ! ($count >= $this->minimum)) |
|
27 | 16 | { |
|
28 | 2 | $model->errors()->add($attribute, 'count_minimum', array(':minimum' => $this->minimum)); |
|
29 | 2 | } |
|
30 | |||
31 | 16 | if ($this->maximum !== NULL AND ! ($count <= $this->maximum)) |
|
32 | 16 | { |
|
33 | 2 | $model->errors()->add($attribute, 'count_maximum', array(':maximum' => $this->maximum)); |
|
34 | 2 | } |
|
35 | |||
36 | 16 | if ($this->within !== NULL AND ! ($count >= $this->within[0] AND $count <= $this->within[1])) |
|
37 | 16 | { |
|
38 | 4 | $model->errors()->add($attribute, 'count_within', array(':minimum' => $this->within[0], ':maximum' => $this->within[1])); |
|
39 | 4 | } |
|
40 | |||
41 | 16 | if ($this->is !== NULL AND ! ($count == $this->is)) |
|
42 | 16 | { |
|
43 | 3 | $model->errors()->add($attribute, 'count_is', array(':is' => $this->is)); |
|
44 | 3 | } |
|
45 | |||
46 | |||
47 | |||
48 | 16 | } |
|
49 | } |
||
50 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.