| Conditions | 4 |
| Paths | 3 |
| Total Lines | 61 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 62 | public function getTemplateData() : array |
||
| 63 | { |
||
| 64 | $blogPosts = []; |
||
| 65 | |||
| 66 | /** @var Entity\ApplicationEntity $applicationEntity */ |
||
| 67 | $applicationEntity = $this->getApplicationStorage() |
||
| 68 | ->getApplicationByName($this->environmentManager->getSelectedApplication()); |
||
| 69 | |||
| 70 | /** @var Entity\Filesystem\FilesystemEntity[] $publications */ |
||
| 71 | $publications = $this->getFilesystemStorage() |
||
| 72 | ->getPublishedDocuments($applicationEntity->getApplicationId()); |
||
| 73 | |||
| 74 | /** @var Entity\Filesystem\FilesystemEntity $filesystemEntity */ |
||
| 75 | foreach ($publications as $filesystemEntity) { |
||
| 76 | /** @var Entity\Filesystem\FilesystemDocumentEntity $documentEntity */ |
||
| 77 | $documentEntity = $this->getFilesystemDocumentStorage() |
||
| 78 | ->getFilesystemDocumentById($filesystemEntity->getDocumentId()); |
||
| 79 | |||
| 80 | $documentMeta = $this->getFilesystemStorage() |
||
| 81 | ->getPublicationMeta($filesystemEntity->getFilesystemId()); |
||
| 82 | |||
| 83 | $author = $this->getPublicationAuthor( |
||
| 84 | $documentEntity->getAuthorId(), |
||
| 85 | $applicationEntity->getApplicationId() |
||
| 86 | ); |
||
| 87 | $author['mood'] = []; |
||
| 88 | |||
| 89 | if (isset($documentMeta['mood_key']) && isset($documentMeta['mood_name'])) { |
||
| 90 | $author['mood'] = [ |
||
| 91 | $documentMeta['mood_name'], |
||
| 92 | $documentMeta['mood_key'] |
||
| 93 | ]; |
||
| 94 | } |
||
| 95 | |||
| 96 | $blogPosts[] = [ |
||
| 97 | 'author' => $author, |
||
| 98 | 'tags' => $this->getPublicationTags( |
||
| 99 | $applicationEntity->getApplicationId(), |
||
| 100 | $filesystemEntity->getFilesystemId() |
||
| 101 | ), |
||
| 102 | 'category' => $this->getPublicationCategory( |
||
| 103 | $applicationEntity->getApplicationId(), |
||
| 104 | $filesystemEntity->getCategoryId() |
||
| 105 | ), |
||
| 106 | 'publishedAt' => $filesystemEntity->getDatePublished(), |
||
| 107 | 'location' => $documentMeta['location'] ?? '', |
||
| 108 | 'summary' => $filesystemEntity->getDescription(), |
||
| 109 | 'illustration' => $documentMeta['illustration'] ?? '', |
||
| 110 | 'path' => $this->getPublicationPath($filesystemEntity), |
||
| 111 | 'title' => $filesystemEntity->getTitle(), |
||
| 112 | 'contentLead' => $documentEntity->getContentLead(), |
||
| 113 | 'contentBody' => $documentEntity->getContentBody() |
||
| 114 | ]; |
||
| 115 | } |
||
| 116 | |||
| 117 | return [ |
||
| 118 | 'activeMenu' => '', |
||
| 119 | 'blogPosts' => $blogPosts, |
||
| 120 | 'fixPost' => $applicationEntity->getIntroduction(), |
||
| 121 | ]; |
||
| 122 | } |
||
| 123 | |||
| 227 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: