Route::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
/**
3
 * This class represents a single endpoint
4
 *
5
 * PHP version 5.5
6
 *
7
 * @category   OpCacheGUI
8
 * @package    Network
9
 * @author     Pieter Hordijk <[email protected]>
10
 * @copyright  Copyright (c) 2014 Pieter Hordijk <https://github.com/PeeHaa>
11
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
12
 * @version    1.0.0
13
 */
14
namespace OpCacheGUI\Network;
15
16
/**
17
 * This class represents a single endpoint
18
 *
19
 * @category   OpCacheGUI
20
 * @package    Network
21
 * @author     Pieter Hordijk <[email protected]>
22
 */
23
class Route
24
{
25
    /**
26
     * @var string The identifier of this route
27
     */
28
    private $identifier;
29
30
    /**
31
     * @var string The verb of this route
32
     */
33
    private $verb;
34
35
    /**
36
     * @var callable The callback to execute when this route matches
37
     */
38
    private $callback;
39
40
    /**
41
     * Creates instance
42
     *
43
     * @param string   $identifier The identifier of this route
44
     * @param string   $verb       The verb of this route
45
     * @param callable $callback   The callback to execute when this route matches
46
     */
47 5
    public function __construct($identifier, $verb, callable $callback)
48
    {
49 5
        $this->identifier = $identifier;
50 5
        $this->verb       = $verb;
51 5
        $this->callback   = $callback;
52 5
    }
53
54
    /**
55
     * Checks whether the current request matches the route
56
     *
57
     * @param string $identifier The identifier of this route
58
     * @param string $verb       The verb of this route
59
     */
60 4
    public function matchesRequest($identifier, $verb)
61
    {
62 4
        return $this->identifier === $identifier && $this->verb === $verb;
63
    }
64
65
    /**
66
     * Runs the route
67
     *
68
     * @return mixed The result of the callback
69
     */
70 1
    public function run()
71
    {
72 1
        $callback = $this->callback;
73
74 1
        return $callback();
75
    }
76
}
77