1
|
|
|
<?php |
2
|
|
|
namespace CodeDruids; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Black Hole for testing |
6
|
|
|
* |
7
|
|
|
* Testing class that ignores everything while still being valid; wrapper around PHP's many "magic methods" |
8
|
|
|
* @see https://www.php.net/manual/en/language.oop5.magic.php |
9
|
|
|
* |
10
|
|
|
* @author Leith Caldwell <[email protected]> |
11
|
|
|
* @copyright 2020 CodeDruids |
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
13
|
|
|
*/ |
14
|
|
|
class BlackHole |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Constructor |
18
|
|
|
* |
19
|
|
|
* @see https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.constructor |
20
|
|
|
* |
21
|
|
|
* @return void |
|
|
|
|
22
|
|
|
*/ |
23
|
15 |
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
// deliberately empty |
26
|
15 |
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Destructor |
30
|
|
|
* |
31
|
|
|
* @see https://www.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.destructor |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
15 |
|
public function __destruct() |
36
|
|
|
{ |
37
|
|
|
// deliberately empty |
38
|
15 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get class property (magic method) |
42
|
|
|
* |
43
|
|
|
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.get |
44
|
|
|
* |
45
|
|
|
* @param string $name Property to retrieve |
46
|
|
|
* @return mixed The BlackHole instance so it can be chained. |
47
|
|
|
*/ |
48
|
2 |
|
public function __get($name) |
49
|
|
|
{ |
50
|
2 |
|
return $this; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set class property (magic method) |
55
|
|
|
* |
56
|
|
|
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.set |
57
|
|
|
* |
58
|
|
|
* @param string $name Property to set |
59
|
|
|
* @param mixed $value Value to set property to |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
3 |
|
public function __set($name, $value) |
63
|
|
|
{ |
64
|
|
|
// deliberately empty |
65
|
3 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Unset class property (magic method) |
69
|
|
|
* |
70
|
|
|
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.isset |
71
|
|
|
* |
72
|
|
|
* @param string $name Property to check |
73
|
|
|
* @return bool Always true |
74
|
|
|
*/ |
75
|
2 |
|
public function __isset($name) |
76
|
|
|
{ |
77
|
2 |
|
return true; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Unset class property (magic method) |
82
|
|
|
* |
83
|
|
|
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.unset |
84
|
|
|
* |
85
|
|
|
* @param string $name Property to unset |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
2 |
|
public function __unset($name) |
89
|
|
|
{ |
90
|
|
|
// deliberately empty |
91
|
2 |
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Call specific class method in object context (magic method) |
95
|
|
|
* |
96
|
|
|
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.call |
97
|
|
|
* |
98
|
|
|
* @param string $name Method to call |
99
|
|
|
* @param mixed[] $arguments Enumerated array of method parameters |
100
|
|
|
* @return mixed The BlackHole instance so it can be chained. |
101
|
|
|
*/ |
102
|
2 |
|
public function __call($name, $arguments) |
103
|
|
|
{ |
104
|
2 |
|
return $this; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Call specific class method in static context (magic method) |
109
|
|
|
* |
110
|
|
|
* @see https://www.php.net/manual/en/language.oop5.overloading.php#object.callstatic |
111
|
|
|
* |
112
|
|
|
* @param string $name Method to call |
113
|
|
|
* @param mixed[] $arguments Enumerated array of method parameters |
114
|
|
|
* @return mixed A new BlackHole instance so it can be chained. |
115
|
|
|
*/ |
116
|
2 |
|
public static function __callStatic($name, $arguments) |
117
|
|
|
{ |
118
|
2 |
|
return new static; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Serialize class to string (magic method) |
123
|
|
|
* |
124
|
|
|
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.tostring |
125
|
|
|
* |
126
|
|
|
* @return string The fully qualified class name for the object |
127
|
|
|
*/ |
128
|
|
|
public function __toString() |
129
|
|
|
{ |
130
|
|
|
return static::class; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Serialize class to array (magic method) |
135
|
|
|
* |
136
|
|
|
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.serialize |
137
|
|
|
* |
138
|
|
|
* @return mixed Associative array of key-value pairs as object representation |
139
|
|
|
*/ |
140
|
1 |
|
public function __serialize() |
141
|
|
|
{ |
142
|
1 |
|
return []; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Unserialize array of class properties (magic method) |
147
|
|
|
* |
148
|
|
|
* @see https://www.php.net/manual/en/function.unserialize.php |
149
|
|
|
* |
150
|
|
|
* @param mixed[] $data Properties to unserialize back into the class |
151
|
|
|
* @return void |
152
|
|
|
*/ |
153
|
1 |
|
public function __unserialize(array $data) |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
// deliberately empty |
156
|
1 |
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Call object as a function (magic method) |
160
|
|
|
* |
161
|
|
|
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.invoke |
162
|
|
|
* |
163
|
|
|
* @return string The BlackHole instance so it can be chained. |
164
|
|
|
*/ |
165
|
2 |
|
public function __invoke() |
166
|
|
|
{ |
167
|
2 |
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Override object representation for {@see \var_export()} (magic method) |
172
|
|
|
* |
173
|
|
|
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.set-state |
174
|
|
|
* |
175
|
|
|
* @param mixed[] $properties Associative array of exported properties |
176
|
|
|
* @return object A new BlackHole instance so it can be chained. |
177
|
|
|
*/ |
178
|
2 |
|
public static function __set_state($properties) |
179
|
|
|
{ |
180
|
2 |
|
return new static; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Override object representation for {@see \var_dump()} (magic method) |
185
|
|
|
* |
186
|
|
|
* @see https://www.php.net/manual/en/language.oop5.magic.php#object.debuginfo |
187
|
|
|
* |
188
|
|
|
* @return mixed[] No debug information |
189
|
|
|
*/ |
190
|
2 |
|
public function __debugInfo() |
191
|
|
|
{ |
192
|
2 |
|
return []; |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.