| Conditions | 13 |
| Paths | 21 |
| Total Lines | 59 |
| Code Lines | 33 |
| 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 |
||
| 44 | private function processHtmlDocuments( |
||
| 45 | array $items, |
||
| 46 | CDocumentRepository $documentRepo, |
||
| 47 | ResourceNodeRepository $resourceNodeRepo, |
||
| 48 | string $context |
||
| 49 | ): void { |
||
| 50 | $total = \count($items); |
||
| 51 | $processed = 0; |
||
| 52 | $changed = 0; |
||
| 53 | |||
| 54 | foreach ($items as $item) { |
||
| 55 | $processed++; |
||
| 56 | $iid = (int) $item['iid']; |
||
| 57 | |||
| 58 | try { |
||
| 59 | $document = $documentRepo->find($iid); |
||
| 60 | if (!$document) { |
||
| 61 | continue; |
||
| 62 | } |
||
| 63 | |||
| 64 | $resourceNode = $document->getResourceNode(); |
||
| 65 | if (!$resourceNode || !$resourceNode->hasResourceFile()) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | |||
| 69 | $resourceFile = $resourceNode->getResourceFiles()->first(); |
||
| 70 | if (!$resourceFile) { |
||
| 71 | continue; |
||
| 72 | } |
||
| 73 | |||
| 74 | // Update HTML only (skip binaries and non-HTML text) |
||
| 75 | $mime = $resourceFile->getMimeType(); |
||
| 76 | if (!\is_string($mime) || stripos($mime, 'text/html') === false) { |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | $content = $resourceNodeRepo->getResourceNodeFileContent($resourceNode); |
||
| 81 | if (!\is_string($content) || trim($content) === '') { |
||
| 82 | continue; |
||
| 83 | } |
||
| 84 | |||
| 85 | $updatedContent = $this->normalizeLegacyImgPaths($content); |
||
| 86 | |||
| 87 | if ($updatedContent !== $content) { |
||
| 88 | $changed++; |
||
| 89 | if (!self::DRY_RUN) { |
||
| 90 | $documentRepo->updateResourceFileContent($document, $updatedContent); |
||
| 91 | $documentRepo->update($document); |
||
| 92 | } else { |
||
| 93 | error_log("[MIGRATION][DRY_RUN][{$context}] Would update HTML for document iid={$iid}"); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } catch (Exception $e) { |
||
| 97 | error_log("[MIGRATION][{$context}] Error processing iid={$iid}: ".$e->getMessage()); |
||
| 98 | // Continue with the next item |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | error_log(sprintf('[MIGRATION][%s] Processed=%d, Updated=%d (Total candidates=%d)', $context, $processed, $changed, $total)); |
||
| 103 | } |
||
| 133 |
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.