| Conditions | 9 |
| Paths | 9 |
| Total Lines | 75 |
| Code Lines | 41 |
| 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 |
||
| 115 | public function readCallTrace( |
||
| 116 | int $pid, |
||
| 117 | string $php_version, |
||
| 118 | int $executor_globals_address, |
||
| 119 | int $sapi_globals_address, |
||
| 120 | int $depth, |
||
| 121 | TraceCache $trace_cache, |
||
| 122 | ): ?CallTrace { |
||
| 123 | $dereferencer = $this->getDereferencer($pid, $php_version); |
||
| 124 | $eg = $this->getExecutorGlobals($executor_globals_address, $php_version, $dereferencer); |
||
| 125 | if (is_null($eg->current_execute_data)) { |
||
| 126 | return null; |
||
| 127 | } |
||
| 128 | |||
| 129 | $trace_cache->updateCacheKey($this->getGlobalRequestTime($sapi_globals_address, $php_version, $dereferencer)); |
||
| 130 | $cached_deereferencer = $trace_cache->getDereferencer($dereferencer); |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @var ZendExecuteData $current_execute_data |
||
| 134 | * @psalm-ignore-var |
||
| 135 | */ |
||
| 136 | $current_execute_data = $dereferencer->deref($eg->current_execute_data); |
||
| 137 | |||
| 138 | $stack = []; |
||
| 139 | $stack[] = $current_execute_data; |
||
| 140 | for ($i = 0; $i < $depth; $i++) { |
||
| 141 | if (is_null($current_execute_data->prev_execute_data)) { |
||
| 142 | break; |
||
| 143 | } |
||
| 144 | $current_execute_data = $dereferencer->deref($current_execute_data->prev_execute_data); |
||
| 145 | $stack[] = $current_execute_data; |
||
| 146 | } |
||
| 147 | |||
| 148 | $result = []; |
||
| 149 | foreach ($stack as $current_execute_data) { |
||
| 150 | if (is_null($current_execute_data->func)) { |
||
| 151 | $result[] = new CallFrame( |
||
| 152 | '', |
||
| 153 | '<unknown>', |
||
| 154 | '<unknown>', |
||
| 155 | null |
||
| 156 | ); |
||
| 157 | continue; |
||
| 158 | } |
||
| 159 | /** |
||
| 160 | * @var ZendFunction $current_function |
||
| 161 | * @psalm-ignore-var |
||
| 162 | */ |
||
| 163 | $current_function = $cached_deereferencer->deref($current_execute_data->func); |
||
| 164 | |||
| 165 | $function_name = $current_function->getFunctionName($cached_deereferencer) ?? '<main>'; |
||
| 166 | $class_name = $current_function->getClassName($cached_deereferencer) ?? ''; |
||
| 167 | $file_name = $current_function->getFileName($cached_deereferencer) ?? '<unknown>'; |
||
| 168 | |||
| 169 | $opline = null; |
||
| 170 | if ( |
||
| 171 | $file_name !== '<internal>' |
||
| 172 | and $file_name !== '<unknown>' |
||
| 173 | and !is_null($current_execute_data->opline) |
||
| 174 | ) { |
||
| 175 | $opline = $this->readOpline( |
||
| 176 | $php_version, |
||
| 177 | $cached_deereferencer->deref($current_execute_data->opline) |
||
| 178 | ); |
||
| 179 | } |
||
| 180 | |||
| 181 | $result[] = new CallFrame( |
||
| 182 | $class_name, |
||
| 183 | $function_name, |
||
| 184 | $file_name, |
||
| 185 | $opline |
||
| 186 | ); |
||
| 187 | } |
||
| 188 | |||
| 189 | return new CallTrace(...$result); |
||
| 190 | } |
||
| 210 |