| Conditions | 14 |
| Paths | 21 |
| Total Lines | 71 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 124 | public function findGlobals( |
||
| 125 | ProcessSpecifier $process_specifier, |
||
| 126 | TargetPhpSettings $target_php_settings, |
||
| 127 | string $symbol_name, |
||
| 128 | ): int { |
||
| 129 | $tsrm_ls_cache = $this->findTsrmLsCache($process_specifier, $target_php_settings); |
||
| 130 | if (isset($tsrm_ls_cache)) { |
||
| 131 | switch ($target_php_settings->php_version) { |
||
| 132 | case ZendTypeReader::V70: |
||
| 133 | case ZendTypeReader::V71: |
||
| 134 | case ZendTypeReader::V72: |
||
| 135 | case ZendTypeReader::V73: |
||
| 136 | $id_symbol = $symbol_name . '_id'; |
||
| 137 | $globals_id_cdata = $this->getSymbolReader($process_specifier, $target_php_settings) |
||
| 138 | ->read($id_symbol); |
||
| 139 | if (is_null($globals_id_cdata)) { |
||
| 140 | throw new RuntimeException('global symbol id not found'); |
||
| 141 | } |
||
| 142 | $tsrm_ls_cache_dereferenced = $this->integer_reader->read64( |
||
| 143 | new CDataByteReader( |
||
| 144 | $this->memory_reader->read( |
||
| 145 | $process_specifier->pid, |
||
| 146 | $tsrm_ls_cache, |
||
| 147 | 8 |
||
| 148 | ) |
||
| 149 | ), |
||
| 150 | 0 |
||
| 151 | )->toInt(); |
||
| 152 | $globals_id = $this->integer_reader->read32( |
||
| 153 | new CDataByteReader($globals_id_cdata), |
||
| 154 | 0 |
||
| 155 | ); |
||
| 156 | return $this->integer_reader->read64( |
||
| 157 | new CDataByteReader( |
||
| 158 | $this->memory_reader->read( |
||
| 159 | $process_specifier->pid, |
||
| 160 | $tsrm_ls_cache_dereferenced + ($globals_id - 1) * 8, |
||
| 161 | 8 |
||
| 162 | ) |
||
| 163 | ), |
||
| 164 | 0 |
||
| 165 | )->toInt(); |
||
| 166 | |||
| 167 | case ZendTypeReader::V74: |
||
| 168 | case ZendTypeReader::V80: |
||
| 169 | case ZendTypeReader::V81: |
||
| 170 | case ZendTypeReader::V82: |
||
| 171 | case ZendTypeReader::V83: |
||
| 172 | $offset = $symbol_name . '_offset'; |
||
| 173 | $globals_offset_cdata = $this->getSymbolReader( |
||
| 174 | $process_specifier, |
||
| 175 | $target_php_settings |
||
| 176 | )->read($offset); |
||
| 177 | if (is_null($globals_offset_cdata)) { |
||
| 178 | throw new RuntimeException('globals offset not found'); |
||
| 179 | } |
||
| 180 | $globals_offset = $this->integer_reader->read64( |
||
| 181 | new CDataByteReader($globals_offset_cdata), |
||
| 182 | 0 |
||
| 183 | )->toInt(); |
||
| 184 | return $tsrm_ls_cache + $globals_offset; |
||
| 185 | default: |
||
| 186 | throw new \LogicException('this should never happen'); |
||
| 187 | } |
||
| 188 | } |
||
| 189 | $globals_address = $this->getSymbolReader($process_specifier, $target_php_settings) |
||
| 190 | ->resolveAddress($symbol_name); |
||
| 191 | if (is_null($globals_address)) { |
||
| 192 | throw new RuntimeException('global symbol not found ' . $symbol_name); |
||
| 193 | } |
||
| 194 | return $globals_address; |
||
| 195 | } |
||
| 208 |