| Conditions | 12 |
| Paths | 14 |
| Total Lines | 44 |
| Code Lines | 25 |
| 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 |
||
| 34 | protected static function export($value): string |
||
| 35 | { |
||
| 36 | if (null === $value) { |
||
| 37 | return 'null'; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!\is_array($value)) { |
||
| 41 | if ($value instanceof Route) { |
||
| 42 | return self::exportRoute($value); |
||
| 43 | } |
||
| 44 | |||
| 45 | return \str_replace("\n", '\'."\n".\'', \var_export($value, true)); |
||
| 46 | } |
||
| 47 | |||
| 48 | if (!$value) { |
||
|
|
|||
| 49 | return '[]'; |
||
| 50 | } |
||
| 51 | |||
| 52 | $i = 0; |
||
| 53 | $export = '['; |
||
| 54 | |||
| 55 | foreach ($value as $k => $v) { |
||
| 56 | if ($i === $k) { |
||
| 57 | ++$i; |
||
| 58 | } else { |
||
| 59 | $export .= self::export($k) . ' => '; |
||
| 60 | |||
| 61 | if (\is_int($k) && $i < $k) { |
||
| 62 | $i = 1 + $k; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | if (\is_string($v) && 0 === \strpos($v, 'unserialize')) { |
||
| 67 | $v = '\\' . $v . ', '; |
||
| 68 | } elseif ($v instanceof Route) { |
||
| 69 | $v .= self::exportRoute($v); |
||
| 70 | } else { |
||
| 71 | $v = self::export($v) . ', '; |
||
| 72 | } |
||
| 73 | |||
| 74 | $export .= $v; |
||
| 75 | } |
||
| 76 | |||
| 77 | return \substr_replace($export, ']', -2); |
||
| 78 | } |
||
| 186 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.