1 | <?php |
||
11 | trait TypeAssertTrait |
||
12 | { |
||
13 | /** |
||
14 | * Performs a type assertion. |
||
15 | * |
||
16 | * @param mixed $actual |
||
17 | * @param string $expected |
||
18 | * @param string $message |
||
19 | */ |
||
20 | public function typeOf($actual, $expected, $message = '') |
||
26 | |||
27 | /** |
||
28 | * Performs a negated type assertion. |
||
29 | * |
||
30 | * @param mixed $actual |
||
31 | * @param string $expected |
||
32 | * @param string $message |
||
33 | */ |
||
34 | public function notTypeOf($actual, $expected, $message = '') |
||
40 | |||
41 | /** |
||
42 | * Perform a true assertion. |
||
43 | * |
||
44 | * @param mixed $value |
||
45 | * @param string $message |
||
46 | */ |
||
47 | public function isTrue($value, $message = '') |
||
53 | |||
54 | /** |
||
55 | * Perform a false assertion. |
||
56 | * |
||
57 | * @param mixed $value |
||
58 | * @param string $message |
||
59 | */ |
||
60 | public function isFalse($value, $message = '') |
||
66 | |||
67 | /** |
||
68 | * Perform a null assertion. |
||
69 | * |
||
70 | * @param mixed $value |
||
71 | * @param string $message |
||
72 | */ |
||
73 | public function isNull($value, $message = '') |
||
79 | |||
80 | /** |
||
81 | * Perform a negated null assertion. |
||
82 | * |
||
83 | * @param mixed $value |
||
84 | * @param string $message |
||
85 | */ |
||
86 | public function isNotNull($value, $message = '') |
||
92 | |||
93 | /** |
||
94 | * Performs a predicate assertion to check if actual |
||
95 | * value is callable. |
||
96 | * |
||
97 | * @param mixed $value |
||
98 | * @param string $message |
||
99 | */ |
||
100 | public function isCallable($value, $message = '') |
||
106 | |||
107 | /** |
||
108 | * Performs a negated predicate assertion to check if actual |
||
109 | * value is not a callable. |
||
110 | * |
||
111 | * @param mixed $value |
||
112 | * @param string $message |
||
113 | */ |
||
114 | public function isNotCallable($value, $message = '') |
||
120 | |||
121 | /** |
||
122 | * Perform a type assertion for type "object.". |
||
123 | * |
||
124 | * @param mixed $value |
||
125 | * @param string $message |
||
126 | */ |
||
127 | public function isObject($value, $message = '') |
||
131 | |||
132 | /** |
||
133 | * Perform a negative type assertion for type "object.". |
||
134 | * |
||
135 | * @param mixed $value |
||
136 | * @param string $message |
||
137 | */ |
||
138 | public function isNotObject($value, $message = '') |
||
142 | |||
143 | /** |
||
144 | * Perform a type assertion for type "array.". |
||
145 | * |
||
146 | * @param mixed $value |
||
147 | * @param string $message |
||
148 | */ |
||
149 | public function isArray($value, $message = '') |
||
153 | |||
154 | /** |
||
155 | * Performs a negative type assertion for type "array.". |
||
156 | * |
||
157 | * @param mixed $value |
||
158 | * @param string $message |
||
159 | */ |
||
160 | public function isNotArray($value, $message = '') |
||
164 | |||
165 | /** |
||
166 | * Perform a type assertion for type "string.". |
||
167 | * |
||
168 | * @param mixed $value |
||
169 | * @param string $message |
||
170 | */ |
||
171 | public function isString($value, $message = '') |
||
175 | |||
176 | /** |
||
177 | * Perform a negated type assertion for type "string.". |
||
178 | * |
||
179 | * @param mixed $value |
||
180 | * @param string $message |
||
181 | */ |
||
182 | public function isNotString($value, $message = '') |
||
186 | |||
187 | /** |
||
188 | * Performs a predicate assertion to check if actual |
||
189 | * value is numeric. |
||
190 | * |
||
191 | * @param mixed $value |
||
192 | * @param string $message |
||
193 | */ |
||
194 | public function isNumeric($value, $message = '') |
||
200 | |||
201 | /** |
||
202 | * Performs a negated predicate assertion to check if actual |
||
203 | * value is numeric. |
||
204 | * |
||
205 | * @param mixed $value |
||
206 | * @param string $message |
||
207 | */ |
||
208 | public function isNotNumeric($value, $message = '') |
||
214 | |||
215 | /** |
||
216 | * Perform a type assertion for type "integer.". |
||
217 | * |
||
218 | * @param $value |
||
219 | * @param string $message |
||
220 | */ |
||
221 | public function isInteger($value, $message = '') |
||
225 | |||
226 | /** |
||
227 | * Perform a negated type assertion for type "integer.". |
||
228 | * |
||
229 | * @param mixed $value |
||
230 | * @param string $message |
||
231 | */ |
||
232 | public function isNotInteger($value, $message = '') |
||
236 | |||
237 | /** |
||
238 | * Perform a type assertion for type "double.". |
||
239 | * |
||
240 | * @param mixed $value |
||
241 | * @param string $message |
||
242 | */ |
||
243 | public function isDouble($value, $message = '') |
||
247 | |||
248 | /** |
||
249 | * Perform a negated type assertion for type "double.". |
||
250 | * |
||
251 | * @param mixed $value |
||
252 | * @param string $message |
||
253 | */ |
||
254 | public function isNotDouble($value, $message = '') |
||
258 | |||
259 | /** |
||
260 | * Perform a type assertion for type "resource.". |
||
261 | * |
||
262 | * @param mixed $value |
||
263 | * @param string $message |
||
264 | */ |
||
265 | public function isResource($value, $message = '') |
||
269 | |||
270 | /** |
||
271 | * Perform a negated type assertion for type "resource.". |
||
272 | * |
||
273 | * @param mixed $value |
||
274 | * @param string $message |
||
275 | */ |
||
276 | public function isNotResource($value, $message = '') |
||
280 | |||
281 | /** |
||
282 | * Perform a type assertion for type "boolean.". |
||
283 | * |
||
284 | * @param mixed $value |
||
285 | * @param string $message |
||
286 | */ |
||
287 | public function isBoolean($value, $message = '') |
||
291 | |||
292 | /** |
||
293 | * Perform a negated type assertion for type "boolean.". |
||
294 | * |
||
295 | * @param mixed $value |
||
296 | * @param string $message |
||
297 | */ |
||
298 | public function isNotBoolean($value, $message = '') |
||
302 | } |
||
303 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: