| Conditions | 7 |
| Paths | 3 |
| Total Lines | 26 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 7.0222 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 27 | 3 | public function addRoute(Route $route) |
|
| 28 | { |
||
| 29 | 3 | $route->path = RegexDispatcher::normalizePath($route->path); |
|
| 30 | 3 | $route->explodePath = RegexDispatcher::explodePath($route->path); |
|
| 31 | |||
| 32 | 3 | foreach ($route->explodePath as $item) { |
|
| 33 | 3 | $matches = array(); |
|
| 34 | 3 | preg_match($this->regex, $item, $matches); |
|
| 35 | |||
| 36 | 3 | $count = count($matches); |
|
| 37 | |||
| 38 | /** |
||
| 39 | * path == "" // path / home |
||
| 40 | * count == 2 // basic path ex: user |
||
| 41 | * count == 3 // var path ex: {id} |
||
| 42 | * count == 5 // var path with regex ex: {id:[1-9]*} |
||
| 43 | */ |
||
| 44 | 3 | if ($route->path != "" && $count != 0 && $count != 2 && $count != 3 && $count != 5) { |
|
| 45 | throw new \Exception("bad route! path : {$item} {$count}"); |
||
| 46 | } |
||
| 47 | |||
| 48 | 3 | $route->ruleMatches[] = $matches; |
|
| 49 | 3 | } |
|
| 50 | |||
| 51 | 3 | $this->routes[] = $route; |
|
| 52 | 3 | } |
|
| 53 | |||
| 62 |