Conditions | 8 |
Paths | 22 |
Total Lines | 83 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
144 | public function loadAction($nameOrAction, $response) { |
||
145 | $model = null; |
||
146 | if ($nameOrAction instanceof Action) { |
||
147 | $model = $nameOrAction; |
||
148 | $actionName = $nameOrAction->getName(); |
||
149 | } else { |
||
150 | $actionName = $nameOrAction; |
||
151 | } |
||
152 | |||
153 | if (!isset($this->actions[$actionName])) { |
||
154 | throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $actionName, $this->model->getName())); |
||
155 | } |
||
156 | |||
157 | if ($model === null) { |
||
158 | $model = $this->actions[$actionName]['model']; |
||
159 | } |
||
160 | |||
161 | /* @var $action ActionSchema */ |
||
162 | $action = $this->actions[$actionName]['action']; |
||
163 | |||
164 | |||
165 | // check permission |
||
166 | if (!$this->service->getFirewall()->hasActionPermission($model)) { |
||
167 | throw new PermissionDeniedException(sprintf('Can\'t access Action (%s) in Module (%s)', $actionName, $this->model->getName())); |
||
168 | } |
||
169 | |||
170 | // check if a response is given |
||
171 | if (!$action->hasResponse($response)) { |
||
172 | throw new ModuleException(sprintf('No Response (%s) given for Action (%s) in Module (%s)', $response, $actionName, $this->model->getName())); |
||
173 | } |
||
174 | $responseClass = $action->getResponse($response); |
||
175 | |||
176 | if (!class_exists($responseClass)) { |
||
177 | throw new ModuleException(sprintf('Response (%s) not found in Module (%s)', $responseClass, $this->model->getName())); |
||
178 | } |
||
179 | $response = new $responseClass($this, $response); |
||
180 | |||
181 | // gets the action class |
||
182 | $className = $model->getClassName(); |
||
183 | |||
184 | if (!class_exists($className)) { |
||
185 | throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $className, $this->model->getName())); |
||
186 | } |
||
187 | |||
188 | $class = new $className($model, $this, $response); |
||
189 | |||
190 | // // l10n |
||
191 | // $app = $this->getServiceContainer()->getApplication(); |
||
192 | // $lang = $app->getLocalization()->getLanguage()->getAlpha2(); |
||
193 | // $country = $app->getLocalization()->getCountry()->getAlpha2(); |
||
194 | // $l10n = $this->getPath() . 'l10n/'; |
||
195 | // $locale = $lang . '_' . $country; |
||
196 | |||
197 | // // load module l10n |
||
198 | // $this->addL10nFile('module', $l10n, $lang, $locale, $class); |
||
199 | |||
200 | // // load additional l10n files |
||
201 | // if (isset($this->actions[$actionName]['l10n'])) { |
||
202 | // foreach ($this->actions[$actionName]['l10n'] as $file) { |
||
203 | // $this->addL10nFile($file, $l10n, $lang, $locale, $class); |
||
204 | // } |
||
205 | // } |
||
206 | |||
207 | // // load action l10n |
||
208 | // $this->addL10nFile(sprintf('actions/%s', $actionName), $l10n, $lang, $locale, $class); |
||
209 | |||
210 | // // assets |
||
211 | // $page = $app->getPage(); |
||
212 | // $moduleUrl = sprintf('%s/_keeko/modules/%s/', $app->getRootUrl(), $this->getName()); |
||
213 | // if (isset($this->actions[$actionName]['assets']['styles'])) { |
||
214 | // foreach ($this->actions[$actionName]['assets']['styles'] as $style) { |
||
215 | // $page->addStyle($moduleUrl . $style); |
||
216 | // } |
||
217 | // } |
||
218 | |||
219 | // if (isset($this->actions[$actionName]['assets']['scripts'])) { |
||
220 | // foreach ($this->actions[$actionName]['assets']['scripts'] as $script) { |
||
221 | // $page->addScript($moduleUrl . $script); |
||
222 | // } |
||
223 | // } |
||
224 | |||
225 | return $class; |
||
226 | } |
||
227 | |||
258 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.