RoutePattern   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 0
dl 0
loc 94
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A properties() 0 8 2
A get() 0 4 1
A post() 0 4 1
A put() 0 4 1
A delete() 0 4 1
1
<?php
2
3
namespace ByJG\RestServer;
4
5
use Closure;
6
7
class RoutePattern
8
{
9
    /**
10
     * @var string[]
11
     */
12
    protected $properties = [];
13
14
    /**
15
     * RoutePattern constructor.
16
     *
17
     * @param array|string $method
18
     * @param string $pattern
19
     * @param string $handler
20
     * @param Closure|string $function
21
     * @param string|null $class
22
     */
23
    public function __construct($method, $pattern, $handler, $function, $class = null)
24
    {
25
        $this->properties['method'] = $method;
26
        $this->properties['pattern'] = $pattern;
27
        $this->properties['handler'] = $handler;
28
        $this->properties['function'] = $function;
29
        $this->properties['class'] = $class;
30
    }
31
32
    /**
33
     * @param string $property
34
     * @return string
35
     */
36
    public function properties($property = null)
37
    {
38
        if (empty($property)) {
39
            return $this->properties;
40
        }
41
42
        return $this->properties[$property];
43
    }
44
45
    /**
46
     * RoutePattern Factory for "GET" method
47
     *
48
     * @param string $pattern
49
     * @param string $function
50
     * @param string $class
51
     * @param string $handler
52
     * @return RoutePattern
53
     */
54
    public static function get($pattern, $function, $class = null, $handler = null)
55
    {
56
        return new RoutePattern('GET', $pattern, $handler, $function, $class);
57
    }
58
59
    /**
60
     * RoutePattern Factory for "POST" method
61
     *
62
     * @param string $pattern
63
     * @param string $function
64
     * @param string $class
65
     * @param string $handler
66
     * @return RoutePattern
67
     */
68
    public static function post($pattern, $function, $class = null, $handler = null)
69
    {
70
        return new RoutePattern('POST', $pattern, $handler, $function, $class);
71
    }
72
73
    /**
74
     * RoutePattern Factory for "PUT" method
75
     *
76
     * @param string $pattern
77
     * @param string $function
78
     * @param string $class
79
     * @param string $handler
80
     * @return RoutePattern
81
     */
82
    public static function put($pattern, $function, $class = null, $handler = null)
83
    {
84
        return new RoutePattern('PUT', $pattern, $handler, $function, $class);
85
    }
86
87
    /**
88
     * RoutePattern Factory for "DELETE" method
89
     *
90
     * @param string $pattern
91
     * @param string $function
92
     * @param string $class
93
     * @param string $handler
94
     * @return RoutePattern
95
     */
96
    public static function delete($pattern, $function, $class = null, $handler = null)
97
    {
98
        return new RoutePattern('DELETE', $pattern, $handler, $function, $class);
99
    }
100
}
101