Completed
Push — master ( b852c1...ed5538 )
by Pierre
03:14
created

Route::getCallable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Component\Http;
4
5
class Route
6
{
7
8
    protected $method;
9
    protected $expr;
10
    protected $callable;
11
12
    /**
13
     * instanciate
14
     *
15
     * @param string $routeItem
16
     */
17
    public function __construct(string $routeItem)
18
    {
19
        $this->method = 'GET';
20
        $this->expr = '/^(*.)$/';
21
        $this->callable = function () {
22
        };
23
        if (strpos($routeItem, ';') !== false) {
24
            list(
25
                $this->method,
26
                $this->expr,
27
                $this->callable
28
            ) = explode(';', $routeItem);
29
        } else {
30
            $this->expr = $routeItem;
31
        }
32
    }
33
34
    /**
35
     * return regexp pattern
36
     *
37
     * @return string
38
     */
39
    public function getExpr(): string
40
    {
41
        return $this->expr;
42
    }
43
44
    /**
45
     * return required request method
46
     *
47
     * @return string
48
     */
49
    public function getMethod(): string
50
    {
51
        return $this->method;
52
    }
53
54
    /**
55
     * return a nonsense
56
     * @todo refacto this as a pattern group replacer to get params slugs
57
     *
58
     * @return string
59
     */
60
    public function getCallable(): string
61
    {
62
        return $this->callable;
63
    }
64
}
65