Total Complexity | 7 |
Total Lines | 111 |
Duplicated Lines | 0 % |
Coverage | 50% |
Changes | 0 |
1 | <?php |
||
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) |
||
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) |
|
116 | } |
||
117 | } |
||
118 |