Conditions | 7 |
Paths | 6 |
Total Lines | 58 |
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 |
||
113 | public function detailAction() |
||
114 | { |
||
115 | $translator = $this->translator; |
||
116 | $repo = $this->repo; |
||
117 | $id = $this->params('id'); |
||
118 | |||
119 | if(is_null($id)){ |
||
120 | $this->getResponse()->setStatusCode(Response::STATUS_CODE_404); |
||
121 | return [ |
||
122 | 'message' => $translator->translate('Can not access profile page without id'), |
||
123 | 'exception' => new \InvalidArgumentException('Null Organization Profile Id') |
||
124 | ]; |
||
125 | } |
||
126 | |||
127 | $organization = $repo->find($id); |
||
128 | if(!$organization instanceof Organization){ |
||
129 | throw new NotFoundException($id); |
||
130 | } |
||
131 | |||
132 | if( |
||
133 | Organization::PROFILE_DISABLED == $organization->getProfileSetting() |
||
134 | || is_null($organization->getProfileSetting()) |
||
135 | ){ |
||
136 | return $this->disabledProfileViewModel($organization); |
||
137 | } |
||
138 | |||
139 | $result = $this->pagination([ |
||
140 | 'params' => [ |
||
141 | 'Organization_Jobs',[ |
||
142 | 'q', |
||
143 | 'organization_id' => $id, |
||
144 | 'count' => $this->options['count'], |
||
145 | 'page' => 1, |
||
146 | ], |
||
147 | ], |
||
148 | 'paginator' => [ |
||
149 | 'as' => 'jobs', |
||
150 | 'Organizations/ListJob', |
||
151 | ], |
||
152 | ]); |
||
153 | |||
154 | if( |
||
155 | Organization::PROFILE_ACTIVE_JOBS == $organization->getProfileSetting() |
||
156 | ){ |
||
157 | /* @var \Zend\Paginator\Paginator $paginator */ |
||
158 | $paginator = $result['jobs']; |
||
159 | $count = $paginator->getTotalItemCount(); |
||
160 | if(0===$count){ |
||
161 | return $this->disabledProfileViewModel($organization); |
||
162 | } |
||
163 | } |
||
164 | $result['organization'] = $organization; |
||
165 | $result['organizationImageCache'] = $this->imageFileCacheManager; |
||
166 | |||
167 | /* @var \Zend\Mvc\Controller\Plugin\Url $url */ |
||
168 | $result['paginationControlRoute'] = 'lang/organizations/profileDetail'; |
||
169 | return new ViewModel($result); |
||
170 | } |
||
171 | |||
182 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: