Completed
Push — master ( ed5538...a8c82f )
by Pierre
08:46
created

Route::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 2
rs 9.9
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 4
    public function __construct(string $routeItem)
18
    {
19 4
        $this->method = 'GET';
20 4
        $this->expr = '/^(*.)$/';
21
        $this->callable = function () {
22
        };
23 4
        if (strpos($routeItem, ';') !== false) {
24
            list(
25 1
                $this->method,
26 1
                $this->expr,
27 1
                $this->callable
28 1
            ) = explode(';', $routeItem);
29
        } else {
30 4
            $this->expr = $routeItem;
31
        }
32
    }
33
34
    /**
35
     * return regexp pattern
36
     *
37
     * @return string
38
     */
39 2
    public function getExpr(): string
40
    {
41 2
        return $this->expr;
42
    }
43
44
    /**
45
     * return required request method
46
     *
47
     * @return string
48
     */
49 2
    public function getMethod(): string
50
    {
51 2
        return $this->method;
52
    }
53
}
54