Conditions | 11 |
Paths | 23 |
Total Lines | 58 |
Code Lines | 32 |
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 |
||
29 | private function processHtmlFiles(): void |
||
30 | { |
||
31 | // Select only HTML files that are linked to resource links |
||
32 | $sql = " |
||
33 | SELECT rl.resource_node_id, rl.c_id |
||
34 | FROM resource_link rl |
||
35 | JOIN c_document cd ON rl.resource_node_id = cd.resource_node_id |
||
36 | WHERE cd.filetype = 'file' |
||
37 | "; |
||
38 | $result = $this->connection->executeQuery($sql); |
||
39 | $items = $result->fetchAllAssociative(); |
||
40 | |||
41 | $documentRepo = $this->container->get(CDocumentRepository::class); |
||
42 | $resourceNodeRepo = $this->container->get(ResourceNodeRepository::class); |
||
43 | |||
44 | foreach ($items as $item) { |
||
45 | try { |
||
46 | // Find the document by resource node ID |
||
47 | $document = $documentRepo->findOneBy(['resourceNode' => $item['resource_node_id']]); |
||
48 | if (!$document) { |
||
49 | error_log("Document not found for resource node ID {$item['resource_node_id']}"); |
||
50 | continue; |
||
51 | } |
||
52 | |||
53 | // Retrieve the resource node |
||
54 | $resourceNode = $document->getResourceNode(); |
||
55 | if (!$resourceNode || !$resourceNode->hasResourceFile()) { |
||
56 | error_log("Resource node or file not found for document ID {$document->getIid()}"); |
||
57 | continue; |
||
58 | } |
||
59 | |||
60 | // Get the first resource file and validate MIME type |
||
61 | $resourceFile = $resourceNode->getResourceFiles()->first(); |
||
62 | if (!$resourceFile || 'text/html' !== $resourceFile->getMimeType()) { |
||
63 | error_log("Invalid or missing HTML file for document ID {$document->getIid()}"); |
||
64 | continue; |
||
65 | } |
||
66 | |||
67 | // Fetch content of the HTML file |
||
68 | $content = $resourceNodeRepo->getResourceNodeFileContent($resourceNode); |
||
69 | if (!is_string($content) || '' === trim($content)) { |
||
70 | error_log("Empty or invalid content for resource node ID {$item['resource_node_id']}"); |
||
71 | continue; |
||
72 | } |
||
73 | |||
74 | // Update the content with fixed links |
||
75 | $updatedContent = $this->fixHtmlLinks($content, $document->getIid(), $item['resource_node_id'], $item['c_id']); |
||
76 | if ($content !== $updatedContent) { |
||
77 | // Save the updated content back |
||
78 | $documentRepo->updateResourceFileContent($document, $updatedContent); |
||
79 | $documentRepo->update($document); |
||
80 | error_log("Updated content for document ID {$document->getIid()}"); |
||
81 | } else { |
||
82 | error_log("No changes required for document ID {$document->getIid()}"); |
||
83 | } |
||
84 | } catch (Exception $e) { |
||
85 | // Log errors for debugging purposes |
||
86 | error_log("Error processing document with resource node ID {$item['resource_node_id']}: " . $e->getMessage()); |
||
87 | } |
||
158 |
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.