| 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 |
||
| 110 | public function readCallTrace(int $pid, string $php_version, int $executor_globals_address, int $depth): ?CallTrace |
||
| 111 | { |
||
| 112 | $dereferencer = $this->getDereferencer($pid, $php_version); |
||
| 113 | $eg = $this->getExecutorGlobals($executor_globals_address, $php_version, $dereferencer); |
||
| 114 | if (is_null($eg->current_execute_data)) { |
||
| 115 | return null; |
||
| 116 | } |
||
| 117 | /** |
||
| 118 | * @var ZendExecuteData $current_execute_data |
||
| 119 | * @psalm-ignore-var |
||
| 120 | */ |
||
| 121 | $current_execute_data = $dereferencer->deref($eg->current_execute_data); |
||
| 122 | |||
| 123 | $stack = []; |
||
| 124 | $stack[] = $current_execute_data; |
||
| 125 | for ($i = 0; $i < $depth; $i++) { |
||
| 126 | if (is_null($current_execute_data->prev_execute_data)) { |
||
| 127 | break; |
||
| 128 | } |
||
| 129 | $current_execute_data = $dereferencer->deref($current_execute_data->prev_execute_data); |
||
| 130 | $stack[] = $current_execute_data; |
||
| 131 | } |
||
| 132 | |||
| 133 | $result = []; |
||
| 134 | foreach ($stack as $current_execute_data) { |
||
| 135 | if (is_null($current_execute_data->func)) { |
||
| 136 | $result[] = new CallFrame( |
||
| 137 | '', |
||
| 138 | '<unknown>', |
||
| 139 | '<unknown>', |
||
| 140 | null |
||
| 141 | ); |
||
| 142 | continue; |
||
| 143 | } |
||
| 144 | /** |
||
| 145 | * @var ZendFunction $current_function |
||
| 146 | * @psalm-ignore-var |
||
| 147 | */ |
||
| 148 | $current_function = $dereferencer->deref($current_execute_data->func); |
||
| 149 | |||
| 150 | $function_name = $current_function->getFunctionName($dereferencer) ?? '<main>'; |
||
| 151 | $class_name = $current_function->getClassName($dereferencer) ?? ''; |
||
| 152 | $file_name = $current_function->getFileName($dereferencer) ?? '<unknown>'; |
||
| 153 | |||
| 154 | $opline = null; |
||
| 155 | if ($file_name !== '<internal>' and !is_null($current_execute_data->opline)) { |
||
| 156 | $opline = $this->readOpline( |
||
| 157 | $php_version, |
||
| 158 | $dereferencer->deref($current_execute_data->opline) |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 162 | $result[] = new CallFrame( |
||
| 163 | $class_name, |
||
| 164 | $function_name, |
||
| 165 | $file_name, |
||
| 166 | $opline |
||
| 167 | ); |
||
| 168 | } |
||
| 169 | |||
| 170 | return new CallTrace(...$result); |
||
| 171 | } |
||
| 191 |