Conditions | 4 |
Paths | 3 |
Total Lines | 57 |
Code Lines | 27 |
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 |
||
40 | public function getTemplateData() : array |
||
41 | { |
||
42 | $blogPosts = []; |
||
43 | $parameters = $this->getRoutingParameters(); |
||
44 | |||
45 | $userName = $parameters['basename'] ?? ''; |
||
46 | |||
47 | if ($parameters['path'] == '/' || empty($userName)) { |
||
48 | throw new RuntimeException('Forbidden', 403); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @var Entity\UserEntity $userEntity |
||
53 | */ |
||
54 | $userEntity = $this->getUserStorage() |
||
55 | ->getUserByUserName($userName); |
||
56 | |||
57 | /** |
||
58 | * @var array $userMeta |
||
59 | */ |
||
60 | $userMeta = $this->getUserStorage() |
||
61 | ->getSimpleUserMetaListByUser((int) $userEntity->getUserId()); |
||
62 | |||
63 | /** |
||
64 | * @var Entity\ApplicationEntity $applicationEntity |
||
65 | */ |
||
66 | $applicationEntity = $this->getApplicationStorage() |
||
67 | ->getApplicationByName($this->environmentManager->getSelectedApplication()); |
||
68 | |||
69 | /** |
||
70 | * @var Entity\EntitySet $publications |
||
71 | */ |
||
72 | $publications = $this->getFilesystemStorage() |
||
73 | ->getFilesystemPublishedDocumentListByAuthor( |
||
74 | $applicationEntity->getApplicationId(), |
||
75 | $userEntity->getUserId() |
||
76 | ); |
||
77 | |||
78 | /** |
||
79 | * @var Entity\FilesystemPublishedDocumentEntity $publishedDocumentEntity |
||
80 | */ |
||
81 | foreach ($publications as $publishedDocumentEntity) { |
||
82 | $blogPosts[] = $this->getBlobPostData($applicationEntity, $publishedDocumentEntity); |
||
83 | } |
||
84 | |||
85 | return [ |
||
86 | 'activeMenu' => '', |
||
87 | 'user' => [ |
||
88 | 'userId' => $userEntity->getUserId(), |
||
89 | 'userName' => $userEntity->getUserName(), |
||
90 | 'url' => $this->environmentManager->getRequestUri(), |
||
91 | 'meta' => $userMeta, |
||
92 | ], |
||
93 | 'application' => $this->getApplicationData($applicationEntity), |
||
94 | 'blogPosts' => $blogPosts, |
||
95 | ]; |
||
96 | } |
||
97 | } |
||
98 |