| Conditions | 43 |
| Paths | 2334 |
| Total Lines | 190 |
| 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 |
||
| 18 | public function match($rawPathinfo) |
||
| 19 | { |
||
| 20 | $allow = array(); |
||
| 21 | $pathinfo = rawurldecode($rawPathinfo); |
||
| 22 | $trimmedPathinfo = rtrim($pathinfo, '/'); |
||
| 23 | $context = $this->context; |
||
| 24 | $request = $this->request ?: $this->createRequest($pathinfo); |
||
| 25 | $requestMethod = $canonicalMethod = $context->getMethod(); |
||
| 26 | |||
| 27 | if ('HEAD' === $requestMethod) { |
||
| 28 | $canonicalMethod = 'GET'; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (0 === strpos($pathinfo, '/a')) { |
||
| 32 | // a_first |
||
| 33 | if ('/a/11' === $pathinfo) { |
||
| 34 | return array('_route' => 'a_first'); |
||
| 35 | } |
||
| 36 | |||
| 37 | // a_second |
||
| 38 | if ('/a/22' === $pathinfo) { |
||
| 39 | return array('_route' => 'a_second'); |
||
| 40 | } |
||
| 41 | |||
| 42 | // a_third |
||
| 43 | if ('/a/333' === $pathinfo) { |
||
| 44 | return array('_route' => 'a_third'); |
||
| 45 | } |
||
| 46 | |||
| 47 | } |
||
| 48 | |||
| 49 | // a_wildcard |
||
| 50 | if (preg_match('#^/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) { |
||
| 51 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'a_wildcard')), array ()); |
||
| 52 | } |
||
| 53 | |||
| 54 | if (0 === strpos($pathinfo, '/a')) { |
||
| 55 | // a_fourth |
||
| 56 | if ('/a/44' === $trimmedPathinfo) { |
||
| 57 | $ret = array('_route' => 'a_fourth'); |
||
| 58 | if ('/' === substr($pathinfo, -1)) { |
||
| 59 | // no-op |
||
| 60 | } elseif ('GET' !== $canonicalMethod) { |
||
| 61 | goto not_a_fourth; |
||
| 62 | } else { |
||
| 63 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fourth')); |
||
| 64 | } |
||
| 65 | |||
| 66 | return $ret; |
||
| 67 | } |
||
| 68 | not_a_fourth: |
||
| 69 | |||
| 70 | // a_fifth |
||
| 71 | if ('/a/55' === $trimmedPathinfo) { |
||
| 72 | $ret = array('_route' => 'a_fifth'); |
||
| 73 | if ('/' === substr($pathinfo, -1)) { |
||
| 74 | // no-op |
||
| 75 | } elseif ('GET' !== $canonicalMethod) { |
||
| 76 | goto not_a_fifth; |
||
| 77 | } else { |
||
| 78 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_fifth')); |
||
| 79 | } |
||
| 80 | |||
| 81 | return $ret; |
||
| 82 | } |
||
| 83 | not_a_fifth: |
||
| 84 | |||
| 85 | // a_sixth |
||
| 86 | if ('/a/66' === $trimmedPathinfo) { |
||
| 87 | $ret = array('_route' => 'a_sixth'); |
||
| 88 | if ('/' === substr($pathinfo, -1)) { |
||
| 89 | // no-op |
||
| 90 | } elseif ('GET' !== $canonicalMethod) { |
||
| 91 | goto not_a_sixth; |
||
| 92 | } else { |
||
| 93 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'a_sixth')); |
||
| 94 | } |
||
| 95 | |||
| 96 | return $ret; |
||
| 97 | } |
||
| 98 | not_a_sixth: |
||
| 99 | |||
| 100 | } |
||
| 101 | |||
| 102 | // nested_wildcard |
||
| 103 | if (0 === strpos($pathinfo, '/nested') && preg_match('#^/nested/(?P<param>[^/]++)$#sD', $pathinfo, $matches)) { |
||
| 104 | return $this->mergeDefaults(array_replace($matches, array('_route' => 'nested_wildcard')), array ()); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (0 === strpos($pathinfo, '/nested/group')) { |
||
| 108 | // nested_a |
||
| 109 | if ('/nested/group/a' === $trimmedPathinfo) { |
||
| 110 | $ret = array('_route' => 'nested_a'); |
||
| 111 | if ('/' === substr($pathinfo, -1)) { |
||
| 112 | // no-op |
||
| 113 | } elseif ('GET' !== $canonicalMethod) { |
||
| 114 | goto not_nested_a; |
||
| 115 | } else { |
||
| 116 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_a')); |
||
| 117 | } |
||
| 118 | |||
| 119 | return $ret; |
||
| 120 | } |
||
| 121 | not_nested_a: |
||
| 122 | |||
| 123 | // nested_b |
||
| 124 | if ('/nested/group/b' === $trimmedPathinfo) { |
||
| 125 | $ret = array('_route' => 'nested_b'); |
||
| 126 | if ('/' === substr($pathinfo, -1)) { |
||
| 127 | // no-op |
||
| 128 | } elseif ('GET' !== $canonicalMethod) { |
||
| 129 | goto not_nested_b; |
||
| 130 | } else { |
||
| 131 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_b')); |
||
| 132 | } |
||
| 133 | |||
| 134 | return $ret; |
||
| 135 | } |
||
| 136 | not_nested_b: |
||
| 137 | |||
| 138 | // nested_c |
||
| 139 | if ('/nested/group/c' === $trimmedPathinfo) { |
||
| 140 | $ret = array('_route' => 'nested_c'); |
||
| 141 | if ('/' === substr($pathinfo, -1)) { |
||
| 142 | // no-op |
||
| 143 | } elseif ('GET' !== $canonicalMethod) { |
||
| 144 | goto not_nested_c; |
||
| 145 | } else { |
||
| 146 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'nested_c')); |
||
| 147 | } |
||
| 148 | |||
| 149 | return $ret; |
||
| 150 | } |
||
| 151 | not_nested_c: |
||
| 152 | |||
| 153 | } |
||
| 154 | |||
| 155 | elseif (0 === strpos($pathinfo, '/slashed/group')) { |
||
| 156 | // slashed_a |
||
| 157 | if ('/slashed/group' === $trimmedPathinfo) { |
||
| 158 | $ret = array('_route' => 'slashed_a'); |
||
| 159 | if ('/' === substr($pathinfo, -1)) { |
||
| 160 | // no-op |
||
| 161 | } elseif ('GET' !== $canonicalMethod) { |
||
| 162 | goto not_slashed_a; |
||
| 163 | } else { |
||
| 164 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_a')); |
||
| 165 | } |
||
| 166 | |||
| 167 | return $ret; |
||
| 168 | } |
||
| 169 | not_slashed_a: |
||
| 170 | |||
| 171 | // slashed_b |
||
| 172 | if ('/slashed/group/b' === $trimmedPathinfo) { |
||
| 173 | $ret = array('_route' => 'slashed_b'); |
||
| 174 | if ('/' === substr($pathinfo, -1)) { |
||
| 175 | // no-op |
||
| 176 | } elseif ('GET' !== $canonicalMethod) { |
||
| 177 | goto not_slashed_b; |
||
| 178 | } else { |
||
| 179 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_b')); |
||
| 180 | } |
||
| 181 | |||
| 182 | return $ret; |
||
| 183 | } |
||
| 184 | not_slashed_b: |
||
| 185 | |||
| 186 | // slashed_c |
||
| 187 | if ('/slashed/group/c' === $trimmedPathinfo) { |
||
| 188 | $ret = array('_route' => 'slashed_c'); |
||
| 189 | if ('/' === substr($pathinfo, -1)) { |
||
| 190 | // no-op |
||
| 191 | } elseif ('GET' !== $canonicalMethod) { |
||
| 192 | goto not_slashed_c; |
||
| 193 | } else { |
||
| 194 | return array_replace($ret, $this->redirect($rawPathinfo.'/', 'slashed_c')); |
||
| 195 | } |
||
| 196 | |||
| 197 | return $ret; |
||
| 198 | } |
||
| 199 | not_slashed_c: |
||
| 200 | |||
| 201 | } |
||
| 202 | |||
| 203 | if ('/' === $pathinfo && !$allow) { |
||
| 204 | throw new Symfony\Component\Routing\Exception\NoConfigurationException(); |
||
| 205 | } |
||
| 206 | |||
| 207 | throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException(); |
||
| 208 | } |
||
| 210 |