Conditions | 11 |
Paths | 17 |
Total Lines | 35 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
59 | public function isValid($input = null) |
||
60 | { |
||
61 | if ($input === null) { |
||
62 | return false; |
||
63 | } |
||
64 | |||
65 | if (!is_numeric($input) && !$input instanceof DateTimeInterface) { |
||
66 | $this->violations[] = 'numeric'; |
||
67 | |||
68 | return false; |
||
69 | } |
||
70 | |||
71 | if ($input instanceof DateTimeInterface) { |
||
72 | if (is_string($this->min)) { |
||
73 | $this->min = new PhpDateTime($this->min); |
||
74 | } |
||
75 | |||
76 | if (is_string($this->max)) { |
||
77 | $this->max = new PhpDateTime($this->max); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | if ($this->max !== null && $input > $this->max) { |
||
82 | $this->violations[] = 'max'; |
||
83 | |||
84 | return false; |
||
85 | } |
||
86 | |||
87 | if ($this->min !== null && $input < $this->min) { |
||
88 | $this->violations[] = 'min'; |
||
89 | |||
90 | return false; |
||
91 | } |
||
92 | |||
93 | return true; |
||
94 | } |
||
96 |