| Conditions | 14 |
| Paths | 5 |
| Total Lines | 43 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 declare(strict_types=1); |
||
| 166 | private function getData(string $name): mixed |
||
| 167 | { |
||
| 168 | if (!isset($this->data[$name])) { |
||
| 169 | $o = $this->content ?? $this->repository->run('cat-file', ['commit', $this->__toString()]); |
||
| 170 | |||
| 171 | if (empty($o) || 0 !== $this->repository->getExitCode()) { |
||
| 172 | throw new \RuntimeException(\sprintf('Failed to get commit data for "%s"', $this->__toString())); |
||
| 173 | } |
||
| 174 | |||
| 175 | foreach (\explode("\n", $this->data['content'] = $o) as $line) { |
||
| 176 | if (isset($this->data['gpgSign'])) { |
||
| 177 | if (\str_ends_with($line, '-----END PGP SIGNATURE-----')) { |
||
| 178 | $pos = \strpos($o, "-----\n \n\n"); |
||
| 179 | $this->data['message'] = \substr($o, $pos ? $pos + 9 : \strpos($o, "-----\n\n") + 7); |
||
| 180 | break; |
||
| 181 | } |
||
| 182 | |||
| 183 | if (!empty($line)) { |
||
| 184 | $this->data['gpgSign'] .= $line."\n"; |
||
| 185 | } |
||
| 186 | continue; |
||
| 187 | } elseif (empty($line)) { |
||
| 188 | continue; |
||
| 189 | } |
||
| 190 | [$key, $value] = \explode(' ', $line, 2); |
||
| 191 | |||
| 192 | if ('tree' === $key) { |
||
| 193 | $this->data['treeHash'] = $value; |
||
| 194 | } elseif ('parent' === $key) { |
||
| 195 | $this->data['parent'][] = $value; |
||
| 196 | } elseif (\in_array($key, ['author', 'committer'], true)) { |
||
| 197 | \preg_match('/(([^\n]*) <([^\n]*)> (\d+ [+-]\d{4}))/A', $value, $author); |
||
| 198 | $this->data[$key] = new Commit\Identity($author[2], $author[3], \DateTime::createFromFormat('U e O', $author[4].' UTC')); |
||
| 199 | } elseif ('gpgsig' === $key) { |
||
| 200 | $this->data['gpgSign'] = ''; |
||
| 201 | } else { |
||
| 202 | $this->data['message'] = \substr($o, \strpos($o, "\n\n") + 2); |
||
| 203 | break; |
||
| 204 | } |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | return $this->data[$name] ?? null; |
||
| 209 | } |
||
| 211 |