| Conditions | 33 |
| Paths | > 20000 |
| Total Lines | 101 |
| Code Lines | 58 |
| 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 |
||
| 108 | protected function parseRoutes(Routing $routing, $routes, $parent = null) |
||
| 109 | { |
||
| 110 | foreach ($routes as $route) { |
||
| 111 | $pattern = Toolkit::expandDirectives($route->getAttribute('pattern')); |
||
| 112 | $opts = array(); |
||
| 113 | if ($route->hasAttribute('imply')) { |
||
| 114 | $opts['imply'] = Toolkit::literalize($route->getAttribute('imply')); |
||
| 115 | } |
||
| 116 | if ($route->hasAttribute('cut')) { |
||
| 117 | $opts['cut'] = Toolkit::literalize($route->getAttribute('cut')); |
||
| 118 | } |
||
| 119 | if ($route->hasAttribute('stop')) { |
||
| 120 | $opts['stop'] = Toolkit::literalize($route->getAttribute('stop')); |
||
| 121 | } |
||
| 122 | if ($route->hasAttribute('name')) { |
||
| 123 | $opts['name'] = Toolkit::expandDirectives($route->getAttribute('name')); |
||
| 124 | } |
||
| 125 | if ($route->hasAttribute('source')) { |
||
| 126 | $opts['source'] = Toolkit::expandDirectives($route->getAttribute('source')); |
||
| 127 | } |
||
| 128 | if ($route->hasAttribute('constraint')) { |
||
| 129 | $opts['constraint'] = array_map('trim', explode(' ', trim(Toolkit::expandDirectives($route->getAttribute('constraint'))))); |
||
| 130 | } |
||
| 131 | // values which will be set when the route matched |
||
| 132 | if ($route->hasAttribute('controller')) { |
||
| 133 | $opts['controller'] = Toolkit::expandDirectives($route->getAttribute('controller')); |
||
| 134 | } |
||
| 135 | if ($route->hasAttribute('locale')) { |
||
| 136 | $opts['locale'] = Toolkit::expandDirectives($route->getAttribute('locale')); |
||
| 137 | } |
||
| 138 | if ($route->hasAttribute('method')) { |
||
| 139 | $opts['method'] = Toolkit::expandDirectives($route->getAttribute('method')); |
||
| 140 | } |
||
| 141 | if ($route->hasAttribute('module')) { |
||
| 142 | $opts['module'] = Toolkit::expandDirectives($route->getAttribute('module')); |
||
| 143 | } |
||
| 144 | if ($route->hasAttribute('output_type')) { |
||
| 145 | $opts['output_type'] = Toolkit::expandDirectives($route->getAttribute('output_type')); |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($route->has('ignores')) { |
||
| 149 | /** @var XmlConfigDomElement $ignore */ |
||
| 150 | foreach ($route->get('ignores') as $ignore) { |
||
| 151 | $opts['ignores'][] = $ignore->getValue(); |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($route->has('defaults')) { |
||
| 156 | /** @var XmlConfigDomElement $default */ |
||
| 157 | foreach ($route->get('defaults') as $default) { |
||
| 158 | $opts['defaults'][$default->getAttribute('for')] = $default->getValue(); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | |||
| 162 | if ($route->has('callbacks')) { |
||
| 163 | $opts['callbacks'] = array(); |
||
| 164 | /** @var XmlConfigDomElement $callback */ |
||
| 165 | foreach ($route->get('callbacks') as $callback) { |
||
| 166 | $opts['callbacks'][] = array( |
||
| 167 | 'class' => $callback->getAttribute('class'), |
||
| 168 | 'parameters' => $callback->getAgaviParameters(), |
||
| 169 | ); |
||
| 170 | } |
||
| 171 | } |
||
| 172 | |||
| 173 | $opts['parameters'] = $route->getAgaviParameters(); |
||
| 174 | |||
| 175 | if (isset($opts['name']) && $parent) { |
||
| 176 | // don't overwrite $parent since it's used later |
||
| 177 | $parentName = $parent; |
||
| 178 | if ($opts['name'][0] == '.') { |
||
| 179 | while ($parentName && isset($this->unnamedRoutes[$parentName])) { |
||
| 180 | $parentRoute = $routing->getRoute($parentName); |
||
| 181 | $parentName = $parentRoute['opt']['parent']; |
||
| 182 | } |
||
| 183 | $opts['name'] = $parentName . $opts['name']; |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | if (isset($opts['controller']) && $parent) { |
||
| 188 | if ($opts['controller'][0] == '.') { |
||
| 189 | $parentRoute = $routing->getRoute($parent); |
||
| 190 | // unwind all empty 'controller' attributes of the parent(s) |
||
| 191 | while ($parentRoute && empty($parentRoute['opt']['controller'])) { |
||
| 192 | $parentRoute = $routing->getRoute($parentRoute['opt']['parent']); |
||
| 193 | } |
||
| 194 | if (!empty($parentRoute['opt']['controller'])) { |
||
| 195 | $opts['controller'] = $parentRoute['opt']['controller'] . $opts['controller']; |
||
| 196 | } |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | $name = $routing->addRoute($pattern, $opts, $parent); |
||
| 201 | if (!isset($opts['name']) || $opts['name'] !== $name) { |
||
| 202 | $this->unnamedRoutes[$name] = true; |
||
| 203 | } |
||
| 204 | if ($route->has('routes')) { |
||
| 205 | $this->parseRoutes($routing, $route->get('routes'), $name); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: