| Conditions | 12 |
| Paths | 9 |
| Total Lines | 31 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 106 | protected function packValue($value): string |
||
| 107 | { |
||
| 108 | if ($value instanceof DeclarationInterface) { |
||
| 109 | //No indentation here |
||
| 110 | return $value->render(); |
||
| 111 | } |
||
| 112 | |||
| 113 | if ($value === null) { |
||
| 114 | return 'null'; |
||
| 115 | } |
||
| 116 | |||
| 117 | if (is_bool($value)) { |
||
| 118 | return ($value ? 'true' : 'false'); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (is_object($value) && method_exists($value, '__set_state')) { |
||
| 122 | return '\\' . var_export($value, true); |
||
| 123 | } |
||
| 124 | |||
| 125 | if (!is_string($value) && !is_numeric($value)) { |
||
| 126 | throw new SerializeException('Unable to pack non scalar value'); |
||
| 127 | } |
||
| 128 | |||
| 129 | if (is_string($value) && class_exists($value)) { |
||
| 130 | $reflection = new ReflectionClass($value); |
||
| 131 | if ($value === $reflection->getName()) { |
||
| 132 | return '\\' . $reflection->getName() . '::class'; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | return var_export($value, true); |
||
| 137 | } |
||
| 139 |