| Conditions | 18 |
| Paths | 685 |
| Total Lines | 76 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 194 | private function readLegacyHtml( |
||
| 195 | PersonalFileRepository $personalRepo, |
||
| 196 | ResourceNodeRepository $rnRepo, |
||
| 197 | PersonalFile $pf |
||
| 198 | ): ?string { |
||
| 199 | // Repository helper |
||
| 200 | try { |
||
| 201 | $content = $personalRepo->getResourceFileContent($pf); |
||
| 202 | if (is_string($content) && $content !== '') { |
||
| 203 | return $content; |
||
| 204 | } |
||
| 205 | } catch (\Throwable $e) { |
||
| 206 | $this->dbg('[info] PF read via repository failed: '.$e->getMessage()); |
||
| 207 | } |
||
| 208 | |||
| 209 | // FileSystem paths |
||
| 210 | try { |
||
| 211 | /** @var ResourceNode|null $node */ |
||
| 212 | $node = $pf->getResourceNode(); |
||
| 213 | if ($node) { |
||
| 214 | $fs = $rnRepo->getFileSystem(); |
||
| 215 | if ($fs) { |
||
| 216 | $basePath = rtrim((string) $node->getPath(), '/'); |
||
| 217 | |||
| 218 | $sharded = static function (string $filename): string { |
||
| 219 | $a = $filename[0] ?? '_'; |
||
| 220 | $b = $filename[1] ?? '_'; |
||
| 221 | $c = $filename[2] ?? '_'; |
||
| 222 | return sprintf('resource/%s/%s/%s/%s', $a, $b, $c, $filename); |
||
| 223 | }; |
||
| 224 | |||
| 225 | foreach ($node->getResourceFiles() as $rf) { |
||
| 226 | $candidates = []; |
||
| 227 | |||
| 228 | $t = (string) $rf->getTitle(); |
||
| 229 | $o = (string) $rf->getOriginalName(); |
||
| 230 | |||
| 231 | if ($t !== '') { |
||
| 232 | if ($basePath !== '') { |
||
| 233 | $candidates[] = $basePath.'/'.$t; |
||
| 234 | } |
||
| 235 | $candidates[] = $sharded($t); |
||
| 236 | } |
||
| 237 | if ($o !== '') { |
||
| 238 | if ($basePath !== '') { |
||
| 239 | $candidates[] = $basePath.'/'.$o; |
||
| 240 | } |
||
| 241 | $candidates[] = $sharded($o); |
||
| 242 | } |
||
| 243 | |||
| 244 | foreach ($candidates as $p) { |
||
| 245 | if ($fs->fileExists($p)) { |
||
| 246 | $data = $fs->read($p); |
||
| 247 | if (is_string($data) && $data !== '') { |
||
| 248 | return $data; |
||
| 249 | } |
||
| 250 | } |
||
| 251 | } |
||
| 252 | } |
||
| 253 | } |
||
| 254 | } |
||
| 255 | } catch (\Throwable $e) { |
||
| 256 | $this->dbg('[info] PF read via filesystem failed: '.$e->getMessage()); |
||
| 257 | } |
||
| 258 | |||
| 259 | // Final fallback: generic node default content (may still fail) |
||
| 260 | try { |
||
| 261 | $node = $pf->getResourceNode(); |
||
| 262 | if ($node) { |
||
| 263 | return $rnRepo->getResourceNodeFileContent($node); |
||
| 264 | } |
||
| 265 | } catch (\Throwable $e) { |
||
| 266 | $this->dbg('[info] PF read via node fallback failed: '.$e->getMessage()); |
||
| 267 | } |
||
| 268 | |||
| 269 | return null; |
||
| 270 | } |
||
| 272 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.