RouteGroup::addRoute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
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
  }