| Conditions | 16 |
| Paths | 47 |
| Total Lines | 42 |
| 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 |
||
| 107 | public function verify($value) |
||
| 108 | { |
||
| 109 | if ($this->has('value-range')) { |
||
| 110 | $valueRange = $this->get('value-range'); |
||
| 111 | if ($value > $valueRange[1] || $value < $valueRange[0]) { |
||
| 112 | return false; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | if ($this->has('value-list')) { |
||
| 117 | $valueList = $this->get('value-list'); |
||
| 118 | $valueList = Arr::pluck($valueList, 'value'); |
||
| 119 | |||
| 120 | if (!in_array($value, $valueList)) { |
||
| 121 | return false; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | switch ($this->format) { |
||
| 126 | case 'bool': |
||
| 127 | return in_array($value, [ |
||
| 128 | true, |
||
| 129 | false, |
||
| 130 | 1, |
||
| 131 | 0, |
||
| 132 | ]); |
||
| 133 | break; |
||
| 134 | case 'uint8': |
||
| 135 | case 'uint16': |
||
| 136 | case 'uint32': |
||
| 137 | case 'int8': |
||
| 138 | case 'int16': |
||
| 139 | case 'int32': |
||
| 140 | case 'int64': |
||
| 141 | return is_int($value); |
||
| 142 | break; |
||
| 143 | case 'float': |
||
| 144 | return is_float($value); |
||
| 145 | break; |
||
| 146 | case 'string': |
||
| 147 | return is_string($value); |
||
| 148 | break; |
||
| 149 | } |
||
| 177 |