Completed
Push — master ( ebff66...d47983 )
by Markus
06:38 queued 02:43
created

CRouteBasic   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 73
rs 10
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 7 1
A match() 0 7 2
A handle() 0 4 1
A setName() 0 5 1
1
<?php
2
3
namespace Anax\Route;
4
5
/**
6
 * A container for routes.
7
 *
8
 */
9
class CRouteBasic
10
{
11
12
    /**
13
    * Properties
14
    *
15
    */
16
    private $name;   // A name for this route
17
    private $rule;   // The rule for this route
18
    private $action; // The controller action to handle this route
19
20
21
22
    /**
23
     * Set values for route.
24
     *
25
     * @param string   $rule   for this route
26
     * @param callable $action callable to implement a controller for the route
27
     *
28
     * @return $this
29
     */
30
    public function set($rule, $action)
31
    {
32
        $this->rule = $rule;
33
        $this->action = $action;
34
35
        return $this;
36
    }
37
38
39
40
    /**
41
     * Check if the route matches a query
42
     *
43
     * @param string $query to match against
44
     *
45
     * @return boolean true if query matches the route
46
     */
47
    public function match($query)
48
    {
49
        if ($this->rule === $query) {
50
            return true;
51
        }
52
        return false;
53
    }
54
55
56
57
    /**
58
     * Handle the action for the route.
59
     *
60
     * @return void
61
     */
62
    public function handle()
63
    {
64
        return call_user_func($this->action);
65
    }
66
67
68
69
    /**
70
     * Set the name of the route.
71
     *
72
     * @param string $name set a name for the route
73
     *
74
     * @return $this
75
     */
76
    public function setName($name)
77
    {
78
        $this->name = $name;
79
        return $this;
80
    }
81
}
82