RouteGroup::doMatch()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 8.8571
cc 5
eloc 11
nc 5
nop 1
crap 5
1
<?php
2
3
4
  namespace ReRoute\Route;
5
6
7
  use ReRoute\RequestContext;
8
  use ReRoute\RouteMatch;
9
10
  /**
11
   * @package ReRoute\AbstractRoute
12
   */
13
  class RouteGroup extends AbstractRoute {
14
15
    /**
16
     * @var AbstractRoute[]
17
     */
18
    protected $routes = [];
19
20
21
    /**
22
     * @param AbstractRoute $route
23
     * @return $this
24
     */
25 51
    public function addRoute(AbstractRoute $route) {
26 51
      $this->routes[] = $route;
27 51
      $route->setParentRoute($this);
28 51
      return $this;
29
    }
30
31
32
    /**
33
     * @return AbstractRoute[]
34
     */
35 54
    public function getRoutes() {
36 54
      return $this->routes;
37
    }
38
39
40
    /**
41
     * @inheritdoc
42
     */
43 36
    public function doMatch(RequestContext $requestContext) {
44 36
      if (empty($this->getRoutes())) {
45 3
        throw new \Exception('Routes list can\'t be empty!');
46
      }
47
      
48 33
      if (false == $this->isMatched($requestContext)) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
49 6
        return false;
50
      }
51
52 27
      foreach ($this->getRoutes() as $route) {
53 27
        $routeMatch = $route->doMatch($requestContext);
54 27
        if ($routeMatch instanceof RouteMatch) {
55 21
          $routeMatch = $this->storeParametersToRouteMatch($routeMatch);
56 21
          return $routeMatch;
57
        }
58 12
      }
59 6
      return false;
60
    }
61
62
  }