Passed
Pull Request — master (#24)
by Raed
04:43
created

GeoCallback   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 111
ccs 10
cts 20
cp 0.5
rs 10
c 0
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setName() 0 5 1
A setArguments() 0 5 1
A __invoke() 0 3 1
A __construct() 0 5 1
A setAction() 0 5 1
A getName() 0 3 1
A getAction() 0 3 1
1
<?php
2
3
namespace LaraCrafts\GeoRoutes;
4
5
class GeoCallback
6
{
7
    #use Serializable;
8
9
    /**
10
     * The callback's name
11
     *
12
     * @var string
13
     */
14
    protected $name;
15
16
    /**
17
     * The callback's action
18
     *
19
     * @var callable
20
     */
21
    protected $action;
22
23
    /**
24
     * The callback arguments
25
     *
26
     * @var array
27
     */
28
    protected $arguments;
29
30
    /**
31
     * Create a new GeoCallback instance
32
     *
33
     * @param string $name
34
     * @param callable $action
35
     * @param array|null $arguments
36
     *
37
     * @return void
38
     */
39 40
    public function __construct(string $name, callable $action, array $arguments = null)
40
    {
41 40
        $this->name = $name;
42 40
        $this->action = $action;
43 40
        $this->arguments = $arguments;
44 40
    }
45
46
    /**
47
     * Call the callback
48
     *
49
     * @return void
50
     */
51 70
    public function __invoke()
52
    {
53 70
        return call_user_func_array($this->action, $this->arguments ?? []);
54
    }
55
56
    /**
57
     * Get the callback's name
58
     *
59
     * @return string
60
     */
61
    public function getName()
62
    {
63
        return $this->name;
64
    }
65
66
    /**
67
     * Set the callback's name
68
     *
69
     * @param string $name
70
     *
71
     * @return $this
72
     */
73
    public function setName(string $name)
74
    {
75
        $this->name = $name;
76
77
        return $this;
78
    }
79
80
    /**
81
     * Get the callback's action
82
     *
83
     * @return callable
84
     */
85
    public function getAction()
86
    {
87
        return $this->action;
88
    }
89
90
    /**
91
     * Set the callback's action
92
     *
93
     * @param callable $action
94
     *
95
     * @return $this
96
     */
97
    public function setAction(callable $action)
98
    {
99
        $this->action = $action;
100
101
        return $this;
102
    }
103
104
    /**
105
     * Set the callback arguments
106
     *
107
     * @param array $arguments
108
     *
109
     * @return $this
110
     */
111 40
    public function setArguments(array $arguments)
112
    {
113 40
        $this->arguments = $arguments;
114
115 40
        return $this;
116
    }
117
}
118