Conditions | 16 |
Paths | 15 |
Total Lines | 61 |
Code Lines | 40 |
Lines | 33 |
Ratio | 54.1 % |
Changes | 4 | ||
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 |
||
58 | protected function addUrl(array $urlParts, SplashRouteInterface $callback) |
||
59 | { |
||
60 | if (!empty($urlParts)) { |
||
61 | $key = array_shift($urlParts); |
||
62 | |||
63 | if ($key == '*') { |
||
64 | // Wildcard URL |
||
65 | if (!empty($urlParts)) { |
||
66 | throw new SplashException('Sorry, the URL pattern /foo/*/bar is not supported. The wildcard (*) must be at the end of an URL'); |
||
67 | } |
||
68 | |||
69 | $httpMethods = $callback->getHttpMethods(); |
||
70 | View Code Duplication | if (empty($httpMethods)) { |
|
|
|||
71 | if (isset($this->wildcardCallbacks[''])) { |
||
72 | throw new SplashException("An error occured while looking at the list URL managed in Splash. The URL '".$callback->getUrl()."' is associated " |
||
73 | ."to 2 methods: \$".$callback->getControllerInstanceName().'->'.$callback->getMethodName()." and \$".$this->wildcardCallbacks['']->getControllerInstanceName().'->'.$this->wildcardCallbacks['']->getMethodName()); |
||
74 | } |
||
75 | $this->wildcardCallbacks[''] = $callback; |
||
76 | } else { |
||
77 | foreach ($httpMethods as $httpMethod) { |
||
78 | if (isset($this->wildcardCallbacks[$httpMethod])) { |
||
79 | throw new SplashException("An error occured while looking at the list URL managed in Splash. The URL '".$callback->getUrl()."' for HTTP method '".$httpMethod."' is associated " |
||
80 | ."to 2 methods: \$".$callback->getControllerInstanceName().'->'.$callback->getMethodName()." and \$".$this->wildcardCallbacks[$httpMethod]->getControllerInstanceName().'->'.$this->wildcardCallbacks[$httpMethod]->getMethodName()); |
||
81 | } |
||
82 | $this->wildcardCallbacks[$httpMethod] = $callback; |
||
83 | } |
||
84 | } |
||
85 | } elseif (strpos($key, '{') === 0 && strpos($key, '}') === strlen($key) - 1) { |
||
86 | // Parameterized URL element |
||
87 | $varName = substr($key, 1, strlen($key) - 2); |
||
88 | |||
89 | if (!isset($this->parameterizedChildren[$varName])) { |
||
90 | $this->parameterizedChildren[$varName] = new self(); |
||
91 | } |
||
92 | $this->parameterizedChildren[$varName]->addUrl($urlParts, $callback); |
||
93 | } else { |
||
94 | // Usual URL element |
||
95 | if (!isset($this->children[$key])) { |
||
96 | $this->children[$key] = new self(); |
||
97 | } |
||
98 | $this->children[$key]->addUrl($urlParts, $callback); |
||
99 | } |
||
100 | View Code Duplication | } else { |
|
101 | $httpMethods = $callback->getHttpMethods(); |
||
102 | if (empty($httpMethods)) { |
||
103 | if (isset($this->callbacks[''])) { |
||
104 | throw new SplashException("An error occured while looking at the list URL managed in Splash. The URL '".$callback->getUrl()."' is associated " |
||
105 | ."to 2 methods: \$".$callback->getControllerInstanceName().'->'.$callback->getMethodName()." and \$".$this->callbacks['']->getControllerInstanceName().'->'.$this->callbacks['']->getMethodName()); |
||
106 | } |
||
107 | $this->callbacks[''] = $callback; |
||
108 | } else { |
||
109 | foreach ($httpMethods as $httpMethod) { |
||
110 | if (isset($this->callbacks[$httpMethod])) { |
||
111 | throw new SplashException("An error occured while looking at the list URL managed in Splash. The URL '".$callback->getUrl()."' for HTTP method '".$httpMethod."' is associated " |
||
112 | ."to 2 methods: \$".$callback->getControllerInstanceName().'->'.$callback->getMethodName()." and \$".$this->callbacks[$httpMethod]->getControllerInstanceName().'->'.$this->callbacks[$httpMethod]->getMethodName()); |
||
113 | } |
||
114 | $this->callbacks[$httpMethod] = $callback; |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | |||
194 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.