RouteGroup   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addRoute() 0 5 1
A getRoutes() 0 3 1
B doMatch() 0 18 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
  }