Conditions | 11 |
Paths | 11 |
Total Lines | 35 |
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 |
||
78 | protected function operandToString($value): string |
||
79 | { |
||
80 | switch (true) { |
||
81 | case $value instanceof ValueInterface: |
||
82 | return $value->toString(); |
||
83 | |||
84 | case $value instanceof TypeInterface: |
||
85 | return '$' . $value->getName(); |
||
86 | |||
87 | case $value instanceof JoinableOpcode: |
||
88 | return '!' . $value->getId(); |
||
89 | |||
90 | case $value instanceof OpcodeInterface: |
||
91 | return $value->getName(); |
||
92 | |||
93 | case $value instanceof Readable: |
||
94 | return 'file:' . $value->getPathname(); |
||
95 | |||
96 | case \is_bool($value): |
||
97 | return '(php:bool)' . ($value ? 'true' : 'false'); |
||
98 | |||
99 | case $value === null: |
||
100 | return '(php:null)null'; |
||
101 | |||
102 | case \is_scalar($value): |
||
103 | $type = \gettype($value); |
||
104 | $minified = \preg_replace('/\s+/', ' ', (string)$value); |
||
105 | return '(php:' . $type . ')"' . \addcslashes($minified, '"') . '"'; |
||
106 | |||
107 | case \is_object($value): |
||
108 | return \get_class($value) . '#' . \spl_object_hash($value); |
||
109 | } |
||
110 | |||
111 | return ''; |
||
112 | } |
||
113 | |||
156 |