Conditions | 11 |
Paths | 128 |
Total Lines | 34 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 3 | Features | 5 |
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 |
||
16 | public function execute(array $arguments) |
||
17 | { |
||
18 | $actionName = (isset($arguments[0]) ? $arguments[0] : false); |
||
19 | $parameters = (isset($arguments[1]) ? $arguments[1] : array()); |
||
20 | $escapeAmp = (isset($arguments[2]) ? (bool)$arguments[2] : false); |
||
21 | $includeHostScheme = (isset($arguments[3]) ? (bool)$arguments[3] : false); |
||
22 | |||
23 | $baseUrl = $this->getViewHelperService() |
||
24 | ->getContext() |
||
25 | ->getRequest() |
||
26 | ->getBaseUrl(); |
||
27 | |||
28 | if (false === $actionName) { |
||
29 | return (empty($baseUrl) ? '/' : $baseUrl); |
||
30 | } |
||
31 | |||
32 | if (empty($actionName)) { |
||
33 | throw new Exception(sprintf('Empty action name')); |
||
34 | } |
||
35 | |||
36 | if (!is_array($parameters)) { |
||
37 | throw new Exception(sprintf('Parameters should be an array')); |
||
38 | } |
||
39 | |||
40 | $rewriter = $this->getUrlRewriterService(); |
||
41 | $route = $rewriter->reverse($actionName, $parameters, $escapeAmp); |
||
42 | |||
43 | $hostScheme = $this->getViewHelperService()->getContext()->getRequest()->getSchemeAndHttpHost(); |
||
44 | |||
45 | return (false === $route ? |
||
46 | parent::execute($arguments) : |
||
47 | ($includeHostScheme ? $hostScheme : null) . $baseUrl . $route |
||
48 | ); |
||
49 | } |
||
50 | |||
62 | } |