| Conditions | 10 |
| Paths | 19 |
| Total Lines | 49 |
| Code Lines | 28 |
| 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 | private function resolveRouting() |
||
| 109 | { |
||
| 110 | // ルーティングルールからController、Actionを取得 |
||
| 111 | foreach ($this->rules as $path => $ca) { |
||
| 112 | $route = []; |
||
| 113 | $tokens = explode("/", ltrim($path, "/")); |
||
| 114 | $placeholderedParams = []; |
||
| 115 | $keyList = []; |
||
| 116 | |||
| 117 | for ($i = 0; $i < count($tokens); $i++) { |
||
| 118 | $token = $tokens[$i]; |
||
| 119 | // PATH定義にプレースホルダがある場合は正規表現に置き換える |
||
| 120 | if (preg_match('/:(.*?)(?:\/|$)/', $token, $matches)) { |
||
| 121 | $keyList[] = $matches[1]; |
||
| 122 | $token = preg_replace('/(:.*?)(?:\/|$)/', '(.+)', $token); |
||
| 123 | } |
||
| 124 | $tokens[$i] = $token; |
||
| 125 | } |
||
| 126 | // プレースホルダのパラメータをセット |
||
| 127 | $expantionPath = $path; |
||
| 128 | // PATH_INFOの階層数とルーティング定義の階層数が一致すればルーティングがマッチ |
||
| 129 | if (($this->request->pathInfo !== $path) && |
||
| 130 | count(explode('/', $path)) === count(explode('/', $this->request->pathInfo))) { |
||
| 131 | // プレースホルダと実URLをひもづける |
||
| 132 | $pathPattern = "/^\/" . implode("\/", $tokens) . "$/"; |
||
| 133 | if (preg_match($pathPattern, $this->request->pathInfo, $matches)) { |
||
| 134 | for ($j = 1; $j < count($matches); $j++) { |
||
| 135 | $key = $keyList[$j - 1]; |
||
| 136 | $placeholderedParams[$key] = Security::safetyIn($matches[$j]); |
||
| 137 | // プレースホルダを一時展開する |
||
| 138 | $expantionPath = preg_replace('/:[a-zA-Z_]{1}[a-zA-Z0-9_]{0,}/', $matches[$j], $expantionPath, 1); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | |||
| 143 | // プレースホルダを展開済みのパス定義が完全一致したときはController、Actionを展開する |
||
| 144 | if ($this->request->pathInfo === $expantionPath && |
||
| 145 | preg_match('/^(?:([a-z]{1}(?:_(?=[a-z])|[a-z0-9])+))#(?:([a-z]{1}(?:_(?=[a-z])|[a-z0-9])+))$/', $ca, $matches)) { |
||
| 146 | $this->setController($matches[1]); |
||
| 147 | $this->setAction($matches[2]); |
||
| 148 | $this->routingContainer->params = $placeholderedParams; |
||
| 149 | $this->logger->info("Routed path: " . $matches[1] . "#" . $matches[2]); |
||
| 150 | |||
| 151 | // ルーティングルールがマッチした場合は抜ける |
||
| 152 | return true; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | |||
| 156 | return false; |
||
| 157 | } |
||
| 213 |