| Conditions | 5 |
| Paths | 4 |
| Total Lines | 71 |
| Code Lines | 45 |
| 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 |
||
| 47 | public function getTemplateData() : array |
||
| 48 | { |
||
| 49 | $parameters = $this->getRoutingParameters(); |
||
| 50 | $userName = $parameters['uri_parameter'] ?? ''; |
||
| 51 | $user = $this->getUser($userName); |
||
| 52 | $userMeta = $this->getUserMeta((int)$user->getUserId()); |
||
| 53 | |||
| 54 | $blogPosts = []; |
||
| 55 | |||
| 56 | /** @var Entity\ApplicationEntity $applicationEntity */ |
||
| 57 | $applicationEntity = $this->getApplicationStorage() |
||
| 58 | ->getApplicationByName($this->environmentManager->getSelectedApplication()); |
||
| 59 | |||
| 60 | /** @var Entity\Filesystem\FilesystemEntity[] $publications */ |
||
| 61 | $publications = $this->getFilesystemStorage() |
||
| 62 | ->getPublishedDocuments($applicationEntity->getApplicationId()); |
||
| 63 | |||
| 64 | /** @var Entity\Filesystem\FilesystemEntity $filesystemEntity */ |
||
| 65 | foreach ($publications as $filesystemEntity) { |
||
| 66 | /** @var Entity\Filesystem\FilesystemDocumentEntity $documentEntity */ |
||
| 67 | $documentEntity = $this->getFilesystemDocumentStorage() |
||
| 68 | ->getFilesystemDocumentById($filesystemEntity->getDocumentId()); |
||
| 69 | |||
| 70 | // Skip publications from other users |
||
| 71 | if ($documentEntity->getAuthorId() != $user->getUserId()) { |
||
| 72 | continue; |
||
| 73 | } |
||
| 74 | |||
| 75 | $documentMeta = $this->getFilesystemStorage() |
||
| 76 | ->getPublicationMeta($filesystemEntity->getFilesystemId()); |
||
| 77 | |||
| 78 | $author = $this->getPublicationAuthor( |
||
| 79 | $documentEntity->getAuthorId(), |
||
| 80 | $applicationEntity->getApplicationId() |
||
| 81 | ); |
||
| 82 | $author['mood'] = []; |
||
| 83 | |||
| 84 | if (isset($documentMeta['mood_key']) && isset($documentMeta['mood_name'])) { |
||
| 85 | $author['mood'] = [ |
||
| 86 | $documentMeta['mood_name'], |
||
| 87 | $documentMeta['mood_key'] |
||
| 88 | ]; |
||
| 89 | } |
||
| 90 | |||
| 91 | $blogPosts[] = [ |
||
| 92 | 'author' => $author, |
||
| 93 | 'tags' => $this->getPublicationTags( |
||
| 94 | $applicationEntity->getApplicationId(), |
||
| 95 | $filesystemEntity->getFilesystemId() |
||
| 96 | ), |
||
| 97 | 'category' => $this->getPublicationCategory( |
||
| 98 | $applicationEntity->getApplicationId(), |
||
| 99 | $filesystemEntity->getCategoryId() |
||
| 100 | ), |
||
| 101 | 'publishedAt' => $filesystemEntity->getDatePublished(), |
||
| 102 | 'location' => $documentMeta['location'] ?? '', |
||
| 103 | 'summary' => $filesystemEntity->getDescription(), |
||
| 104 | 'illustration' => $documentMeta['illustration'] ?? '', |
||
| 105 | 'path' => $this->getPublicationPath($filesystemEntity), |
||
| 106 | 'title' => $filesystemEntity->getTitle(), |
||
| 107 | 'contentLead' => $documentEntity->getContentLead(), |
||
| 108 | 'contentBody' => $documentEntity->getContentBody() |
||
| 109 | ]; |
||
| 110 | } |
||
| 111 | |||
| 112 | return [ |
||
| 113 | 'user' => $user, |
||
| 114 | 'userMeta' => $userMeta, |
||
| 115 | 'blogPosts' => $blogPosts, |
||
| 116 | ]; |
||
| 117 | } |
||
| 118 | |||
| 139 |