Conditions | 7 |
Paths | 6 |
Total Lines | 58 |
Code Lines | 36 |
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 |
||
109 | public function detailAction() |
||
110 | { |
||
111 | $translator = $this->translator; |
||
112 | $repo = $this->repo; |
||
113 | $id = $this->params('id'); |
||
114 | |||
115 | if(is_null($id)){ |
||
116 | $this->getResponse()->setStatusCode(Response::STATUS_CODE_404); |
||
117 | return [ |
||
118 | 'message' => $translator->translate('Can not access profile page without id'), |
||
119 | 'exception' => new \InvalidArgumentException('Null Organization Profile Id') |
||
120 | ]; |
||
121 | } |
||
122 | |||
123 | $organization = $repo->find($id); |
||
124 | if(!$organization instanceof Organization){ |
||
125 | throw new NotFoundException($id); |
||
126 | } |
||
127 | |||
128 | if( |
||
129 | Organization::PROFILE_DISABLED == $organization->getProfileSetting() |
||
130 | || is_null($organization->getProfileSetting()) |
||
131 | ){ |
||
132 | throw new UnauthorizedAccessException(/*@translate*/ 'This Organization Profile is disabled'); |
||
133 | } |
||
134 | |||
135 | $result = $this->pagination([ |
||
136 | 'params' => [ |
||
137 | 'Organization_Jobs',[ |
||
138 | 'q', |
||
139 | 'organization_id' => $organization->getId(), |
||
140 | 'count' => $this->options['count'], |
||
141 | 'page' => 1, |
||
142 | ], |
||
143 | ], |
||
144 | 'paginator' => [ |
||
145 | 'as' => 'jobs', |
||
146 | 'Organizations/ListJob', |
||
147 | ], |
||
148 | ]); |
||
149 | |||
150 | if( |
||
151 | Organization::PROFILE_ACTIVE_JOBS == $organization->getProfileSetting() |
||
152 | ){ |
||
153 | /* @var \Zend\Paginator\Paginator $paginator */ |
||
154 | $paginator = $result['jobs']; |
||
155 | $count = $paginator->getTotalItemCount(); |
||
156 | if(0===$count){ |
||
157 | throw new UnauthorizedAccessException($this->translator->translate('This Organization Profile is disabled')); |
||
158 | } |
||
159 | } |
||
160 | $result['organization'] = $organization; |
||
161 | $result['organizationImageCache'] = $this->imageFileCacheManager; |
||
162 | |||
163 | /* @var \Zend\Mvc\Controller\Plugin\Url $url */ |
||
164 | $result['paginationControlRoute'] = 'lang/organizations/profileDetail'; |
||
165 | return new ViewModel($result); |
||
166 | } |
||
167 | } |
||
168 |
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: