Conditions | 8 |
Paths | 9 |
Total Lines | 61 |
Code Lines | 36 |
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 |
||
91 | public function readCallTrace(int $pid, string $php_version, int $executor_globals_address, int $depth): ?CallTrace |
||
92 | { |
||
93 | $dereferencer = $this->getDereferencer($pid, $php_version); |
||
94 | $eg = $this->getExecutorGlobals($executor_globals_address, $php_version, $dereferencer); |
||
95 | if (is_null($eg->current_execute_data)) { |
||
96 | return null; |
||
97 | } |
||
98 | /** |
||
99 | * @var ZendExecuteData $current_execute_data |
||
100 | * @psalm-ignore-var |
||
101 | */ |
||
102 | $current_execute_data = $dereferencer->deref($eg->current_execute_data); |
||
103 | |||
104 | $stack = []; |
||
105 | $stack[] = $current_execute_data; |
||
106 | for ($i = 0; $i < $depth; $i++) { |
||
107 | if (is_null($current_execute_data->prev_execute_data)) { |
||
108 | break; |
||
109 | } |
||
110 | $current_execute_data = $dereferencer->deref($current_execute_data->prev_execute_data); |
||
111 | $stack[] = $current_execute_data; |
||
112 | } |
||
113 | |||
114 | $result = []; |
||
115 | foreach ($stack as $current_execute_data) { |
||
116 | if (is_null($current_execute_data->func)) { |
||
117 | $result[] = new CallFrame( |
||
118 | '', |
||
119 | '<unknown>', |
||
120 | '<unknown>', |
||
121 | null |
||
122 | ); |
||
123 | continue; |
||
124 | } |
||
125 | /** |
||
126 | * @var ZendFunction $current_function |
||
127 | * @psalm-ignore-var |
||
128 | */ |
||
129 | $current_function = $dereferencer->deref($current_execute_data->func); |
||
130 | |||
131 | $function_name = $current_function->getFunctionName($dereferencer) ?? '<main>'; |
||
132 | $class_name = $current_function->getClassName($dereferencer) ?? ''; |
||
133 | $file_name = $current_function->getFileName($dereferencer) ?? '<unknown>'; |
||
134 | |||
135 | $opline = null; |
||
136 | if ($file_name !== '<internal>' and !is_null($current_execute_data->opline)) { |
||
137 | $opline = $this->readOpline( |
||
138 | $php_version, |
||
139 | $dereferencer->deref($current_execute_data->opline) |
||
140 | ); |
||
141 | } |
||
142 | |||
143 | $result[] = new CallFrame( |
||
144 | $class_name, |
||
145 | $function_name, |
||
146 | $file_name, |
||
147 | $opline |
||
148 | ); |
||
149 | } |
||
150 | |||
151 | return new CallTrace(...$result); |
||
152 | } |
||
172 |