| Conditions | 10 |
| Paths | 15 |
| Total Lines | 24 |
| Code Lines | 19 |
| 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 |
||
| 14 | 525 | public static function isValid(array $data) |
|
| 15 | { |
||
| 16 | 525 | $index = array(); |
|
| 17 | 525 | foreach ($data as $value) { |
|
| 18 | 507 | if (is_array($value) || $value instanceof \stdClass) { |
|
| 19 | 54 | $value = json_encode($value); |
|
| 20 | 489 | } elseif (is_bool($value)) { |
|
| 21 | 41 | $value = '_B' . $value; |
|
| 22 | 489 | } elseif (is_string($value)) { |
|
| 23 | 456 | $value = '_S' . $value; |
|
| 24 | 64 | } elseif (is_int($value)) { |
|
| 25 | 56 | $value = '_I' . $value; |
|
| 26 | 12 | } elseif (is_float($value)) { |
|
| 27 | 3 | $value = '_F' . $value; |
|
| 28 | 9 | } elseif ($value instanceof ObjectItemContract) { |
|
| 29 | 2 | $value = json_encode($value); |
|
| 30 | } |
||
| 31 | 507 | $tmp = &$index[$value]; |
|
| 32 | 507 | if ($tmp !== null) { |
|
| 33 | 22 | return false; |
|
| 34 | } |
||
| 35 | 507 | $tmp = true; |
|
| 36 | } |
||
| 37 | 506 | return true; |
|
| 38 | } |
||
| 40 | } |