STAHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rest() 0 6 2
A any() 0 6 2
A match() 0 6 2
1
<?php
2
/**
3
 * Setup assigned helper
4
 * User: moyo
5
 * Date: 2018/5/29
6
 * Time: 11:18 AM
7
 */
8
9
namespace Carno\Web\Chips\Router;
10
11
use Carno\Web\Contracts\Router\Methods;
12
13
trait STAHelper
14
{
15
    /**
16
     * @param array $methods
17
     * @param string $uri
18
     * @param callable $processor
19
     * @return static
20
     */
21
    public function match(array $methods, string $uri, callable $processor) : self
22
    {
23
        foreach ($methods as $method) {
24
            $this->$method($uri, $processor);
25
        }
26
        return $this;
27
    }
28
29
    /**
30
     * @param string $uri
31
     * @param object $controller
32
     * @return static
33
     */
34
    public function rest(string $uri, object $controller) : self
35
    {
36
        foreach (Methods::RESTFUL as $method) {
37
            $this->$method($uri, [$controller, $method]);
38
        }
39
        return $this;
40
    }
41
42
    /**
43
     * @param string $uri
44
     * @param callable $processor
45
     * @return static
46
     */
47
    public function any(string $uri, callable $processor) : self
48
    {
49
        foreach (array_merge(Methods::META, Methods::RESTFUL) as $method) {
50
            $this->$method($uri, $processor);
51
        }
52
        return $this;
53
    }
54
}
55