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 |
||
147 | public function loadAction($nameOrAction, $response) { |
||
148 | $model = null; |
||
149 | if ($nameOrAction instanceof Action) { |
||
150 | $model = $nameOrAction; |
||
151 | $actionName = $nameOrAction->getName(); |
||
152 | } else { |
||
153 | $actionName = $nameOrAction; |
||
154 | } |
||
155 | |||
156 | if (!isset($this->actions[$actionName])) { |
||
157 | throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $actionName, $this->model->getName())); |
||
158 | } |
||
159 | |||
160 | if ($model === null) { |
||
161 | $model = $this->actions[$actionName]['model']; |
||
162 | } |
||
163 | |||
164 | /* @var $action ActionSchema */ |
||
165 | $action = $this->actions[$actionName]['action']; |
||
166 | |||
167 | |||
168 | // check permission |
||
169 | if (!$this->service->getFirewall()->hasActionPermission($model)) { |
||
170 | throw new PermissionDeniedException(sprintf('Can\'t access Action (%s) in Module (%s)', $actionName, $this->model->getName())); |
||
171 | } |
||
172 | |||
173 | // check if a response is given |
||
174 | if (!$action->hasResponse($response)) { |
||
175 | throw new ModuleException(sprintf('No Response (%s) given for Action (%s) in Module (%s)', $response, $actionName, $this->model->getName())); |
||
176 | } |
||
177 | $responseClass = $action->getResponse($response); |
||
178 | |||
179 | if (!class_exists($responseClass)) { |
||
180 | throw new ModuleException(sprintf('Response (%s) not found in Module (%s)', $responseClass, $this->model->getName())); |
||
181 | } |
||
182 | $response = new $responseClass($this, $response); |
||
183 | |||
184 | // gets the action class |
||
185 | $className = $model->getClassName(); |
||
186 | |||
187 | if (!class_exists($className)) { |
||
188 | throw new ModuleException(sprintf('Action (%s) not found in Module (%s)', $className, $this->model->getName())); |
||
189 | } |
||
190 | |||
191 | $class = new $className($model, $this, $response); |
||
192 | |||
193 | // // l10n |
||
194 | // $app = $this->getServiceContainer()->getApplication(); |
||
195 | // $lang = $app->getLocalization()->getLanguage()->getAlpha2(); |
||
196 | // $country = $app->getLocalization()->getCountry()->getAlpha2(); |
||
197 | // $l10n = $this->getPath() . 'l10n/'; |
||
198 | // $locale = $lang . '_' . $country; |
||
199 | |||
200 | // // load module l10n |
||
201 | // $this->addL10nFile('module', $l10n, $lang, $locale, $class); |
||
202 | |||
203 | // // load additional l10n files |
||
204 | // if (isset($this->actions[$actionName]['l10n'])) { |
||
205 | // foreach ($this->actions[$actionName]['l10n'] as $file) { |
||
206 | // $this->addL10nFile($file, $l10n, $lang, $locale, $class); |
||
207 | // } |
||
208 | // } |
||
209 | |||
210 | // // load action l10n |
||
211 | // $this->addL10nFile(sprintf('actions/%s', $actionName), $l10n, $lang, $locale, $class); |
||
212 | |||
213 | // // assets |
||
214 | // $page = $app->getPage(); |
||
215 | // $moduleUrl = sprintf('%s/_keeko/modules/%s/', $app->getRootUrl(), $this->getName()); |
||
216 | // if (isset($this->actions[$actionName]['assets']['styles'])) { |
||
217 | // foreach ($this->actions[$actionName]['assets']['styles'] as $style) { |
||
218 | // $page->addStyle($moduleUrl . $style); |
||
219 | // } |
||
220 | // } |
||
221 | |||
222 | // if (isset($this->actions[$actionName]['assets']['scripts'])) { |
||
223 | // foreach ($this->actions[$actionName]['assets']['scripts'] as $script) { |
||
224 | // $page->addScript($moduleUrl . $script); |
||
225 | // } |
||
226 | // } |
||
227 | |||
228 | return $class; |
||
229 | } |
||
230 | |||
265 |
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.