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