RouteCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A add() 0 5 1
A get() 0 3 1
A getIterator() 0 3 1
1
<?php
2
3
namespace Controlabs\Routify;
4
5
use ArrayIterator;
6
use Countable;
7
use IteratorAggregate;
8
9
class RouteCollection implements Countable, IteratorAggregate
10
{
11
    /**
12
     * An array of the routes keyed by method.
13
     *
14
     * @var array
15
     */
16
    protected $routes = [];
17
18
    /**
19
     * Add a Route instance to the collection.
20
     *
21
     * @param  \Controlabs\Routify\Route  $route
22
     *
23
     * @return \Controlabs\Routify\Route
24
     */
25
    public function add(Route $route)
26
    {
27
        // $this->routes[$route->method()][$route->uri()] = $route;
28
        $this->routes[$route->method().$route->route()] = $route;
29
        return $route;
30
    }
31
32
    /**
33
     * Get all routes.
34
     *
35
     * @return array
36
     */
37
    public function get()
38
    {
39
        return array_values($this->routes);
40
    }
41
42
    /**
43
     * Get an iterator for the items.
44
     *
45
     * @return \ArrayIterator
46
     */
47
    public function getIterator()
48
    {
49
        return new ArrayIterator($this->get());
50
    }
51
52
    /**
53
     * Count the number of items in the collection.
54
     *
55
     * @return int
56
     */
57
    public function count()
58
    {
59
        return count($this->get());
60
    }
61
}
62