Conditions | 12 |
Paths | 11 |
Total Lines | 33 |
Code Lines | 21 |
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 |
||
64 | function toString($value): string |
||
65 | { |
||
66 | if (\is_object($value) && method_exists($value, '__toString')) { |
||
67 | return $value; |
||
|
|||
68 | } |
||
69 | if (\is_object($value)) { |
||
70 | return 'Object'; |
||
71 | } |
||
72 | if (\is_array($value)) { |
||
73 | return 'Array'; |
||
74 | } |
||
75 | if (\is_callable($value)) { |
||
76 | return 'Function'; |
||
77 | } |
||
78 | if ($value === '') { |
||
79 | return '(empty string)'; |
||
80 | } |
||
81 | if ($value === null) { |
||
82 | return 'null'; |
||
83 | } |
||
84 | if ($value === true) { |
||
85 | return 'true'; |
||
86 | } |
||
87 | if ($value === false) { |
||
88 | return 'false'; |
||
89 | } |
||
90 | if (\is_string($value)) { |
||
91 | return "\"{$value}\""; |
||
92 | } |
||
93 | if (is_scalar($value)) { |
||
94 | return (string)$value; |
||
95 | } |
||
96 | return \gettype($value); |
||
97 | } |
||
116 |