Completed
Branch master (db83f9)
by Arnold
03:38
created

ipv4_in_cidr()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Join an array, using the 'and' parameter as glue the last two items.
5
 *
6
 * @param string $glue
7
 * @param string $and
8
 * @param array  $array
9
 * @return string
10
 */
11
function array_join_pretty($glue, $and, array $array)
12
{
13
    return jasny\array_join_pretty($glue, $and, $array);
14
}
15
16
/**
17
 * Flatten a nested associative array, concatenating the keys.
18
 *
19
 * @param array  $array
20
 * @param string $glue
21
 * @return array
22
 */
23
function array_flatten(array $array, $glue = '.')
24
{
25
    return jasny\array_flatten($array, $glue);
26
}
27
28
/**
29
 * Find a key of an array using a callback function.
30
 * @see array_filter()
31
 *
32
 * Returns the key or FALSE if no element was found.
33
 *
34
 * @param array    $array
35
 * @param callable $callback
36
 * @param int      $flag      Flag determining what arguments are sent to callback
37
 * @return string|int|false
38
 */
39
function array_find_key(array $array, $callback, $flag = 0)
40
{
41
    return jasny\array_find_key($array, $callback, $flag);
42
}
43
44
/**
45
 * Find an element of an array using a callback function.
46
 * @see array_filter()
47
 *
48
 * Returns the value or FALSE if no element was found.
49
     *
50
 * @param array    $array
51
 * @param callable $callback
52
 * @param int      $flag      Flag determining what arguments are sent to callback
53
 * @return mixed|false
54
 */
55
function array_find(array $array, $callback, $flag = 0)
56
{
57
    return jasny\array_find($array, $callback, $flag);
58
}
59
60
/**
61
 * Check if an array contains any value in a set with index check.
62
 *
63
 * @param array $array
64
 * @param array $subset
65
 * @param bool  $strict  Strict type checking
66
 * @return bool
67
 */
68
function array_contains_any_assoc(array $array, array $subset, $strict = false)
69
{
70
    return jasny\array_contains_any_assoc($array, $subset, $strict);
71
}
72
73
/**
74
 * Check if an array contains any value in a set.
75
 **
76
 * @param array $array
77
 * @param array $subset
78
 * @param bool  $strict  Strict type checking
79
 * @return bool
80
 */
81
function array_contains_any(array $array, array $subset, $strict = false)
82
{
83
    return jasny\array_contains_any($array, $subset, $strict);
84
}
85
86
/**
87
 * Check if an array contains all values in a set with index check.
88
 *
89
 * @param array $array
90
 * @param array $subset
91
 * @param bool  $strict  Strict type checking
92
 * @return bool
93
 */
94
function array_contains_all_assoc(array $array, array $subset, $strict = false)
95
{
96
    return jasny\array_contains_all_assoc($array, $subset, $strict);
97
}
98
99
/**
100
 * Check if an array contains all values in a set.
101
 *
102
 * @param array $array
103
 * @param array $subset
104
 * @param bool  $strict  Strict type checking
105
 * @return bool
106
 */
107
function array_contains_all(array $array, array $subset, $strict = false)
108
{
109
    return jasny\array_contains_all($array, $subset, $strict);
110
}
111
112
/**
113
 * Return an array without the specified keys.
114
 *
115
 * @param array          $array
116
 * @param string[]|int[] $keys
117
 * @return array
118
 */
119
function array_without(array $array, array $keys)
120
{
121
    return jasny\array_without($array, $keys);
122
}
123
124
/**
125
 * Return an array with only the specified keys.
126
 *
127
 * @param array          $array
128
 * @param string[]|int[] $keys
129
 * @return array
130
 */
131
function array_only(array $array, array $keys)
132
{
133
    return jasny\array_only($array, $keys);
134
}
135
136
/**
137
 * Turn StudlyCase, camelCase, snake_case or kabab-case into a sentence.
138
 *
139
 * @param string $string
140
 * @return string
141
 */
142
function uncase($string)
143
{
144
    return jasny\uncase($string);
145
}
146
147
/**
148
 * Turn a sentence, camelCase, StudlyCase or snake_case into kabab-case
149
 *
150
 * @param string $string
151
 * @return string
152
 */
153
function kababcase($string)
154
{
155
    return jasny\kababcase($string);
156
}
157
158
/**
159
 * Turn a sentence, camelCase, StudlyCase or kabab-case into snake_case
160
 *
161
 * @param string $string
162
 * @return string
163
 */
164
function snakecase($string)
165
{
166
    return jasny\snakecase($string);
167
}
168
169
/**
170
 * Turn a sentence, camelCase, snake_case or kabab-case into StudlyCase
171
 *
172
 * @param string $string
173
 * @return string
174
 */
175
function studlycase($string)
176
{
177
    return jasny\studlycase($string);
178
}
179
180
/**
181
 * Turn a sentence, camelCase, snake_case or kabab-case into camelCase
182
 *
183
 * @param string $string
184
 * @return string
185
 */
186
function camelcase($string)
187
{
188
    return jasny\camelcase($string);
189
}
190
191
/**
192
 * Match path against an extended wildcard pattern.
193
 *
194
 * @param string $pattern
195
 * @param string $path
196
 * @return bool
197
 */
198
function fnmatch_extended($pattern, $path)
199
{
200
    return jasny\fnmatch_extended($pattern, $path);
201
}
202
203
/**
204
 * Check if the file contains the specified string
205
 *
206
 * @param string $filename
207
 * @param string $str
208
 * @return bool
209
 */
210
function file_contains($filename, $str)
211
{
212
    return jasny\file_contains($filename, $str);
213
}
214
215
/**
216
 * Call a callback with named parameters as associative array.
217
 *
218
 * @param callable $callback
219
 * @param array    $params_arr
220
 * @return mixed
221
 * @throws \BadFunctionCallException
222
 * @throws \ReflectionException
223
 */
224
function call_user_func_assoc($callback, array $params_arr)
225
{
226
    return jasny\call_user_func_assoc($callback, $params_arr);
227
}
228
229
/**
230
 * Set the public properties of an object
231
 *
232
 * @param object $object
233
 * @param array  $data
234
 * @param bool   $dynamic  Set properties not defined in the class
235
 * @return void
236
 */
237
function object_set_properties($object, array $data, $dynamic = false)
238
{
239
    return jasny\object_set_properties($object, $data, $dynamic);
0 ignored issues
show
Bug introduced by
Are you sure the usage of object_set_properties($object, $data, $dynamic) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
240
}
241
242
/**
243
 * Get the public properties of an object.
244
 * This is an alias of `get_object_vars`, except if will always return public properties only.
245
 *
246
 * @param object $object
247
 * @param bool   $dynamic  Get properties not defined in the class
248
 * @return array
249
 */
250
function object_get_properties($object, $dynamic = false)
251
{
252
    return jasny\object_get_properties($object, $dynamic);
253
}
254
255
/**
256
 * Converts inet_pton output to string with bits.
257
 *
258
 * @param string $inet
259
 * @return string
260
 */
261
function inet_to_bits($inet)
262
{
263
    return jasny\inet_to_bits($inet);
264
}
265
266
/**
267
 * Check if IPv6 address is in CIDR block
268
 *
269
 * @param string $ip
270
 * @param string $cidr
271
 * @return bool
272
 */
273
function ipv6_in_cidr($ip, $cidr)
274
{
275
    return jasny\ipv6_in_cidr($ip, $cidr);
276
}
277
278
/**
279
 * Check if IPv4 address is in CIDR block
280
 *
281
 * @param string $ip
282
 * @param string $cidr
283
 * @return bool
284
 */
285
function ipv4_in_cidr($ip, $cidr)
286
{
287
    return jasny\ipv4_in_cidr($ip, $cidr);
288
}
289
290
/**
291
 * Check if IP address is in CIDR block
292
 *
293
 * @param string $ip     An IPv4 or IPv6
294
 * @param string $cidr   An IPv4 CIDR block or IPv6 CIDR block
295
 * @return bool
296
 */
297
function ip_in_cidr($ip, $cidr)
298
{
299
    return jasny\ip_in_cidr($ip, $cidr);
300
}
301
302
/**
303
 * Convert an IPv4 address or CIDR into an IP6 address or CIDR.
304
 *
305
 * @param string $ip
306
 * @return string
307
 * @throws \InvalidArgumentException if ip isn't valid
308
 */
309
function ipv4_to_ipv6($ip)
310
{
311
    return jasny\ipv4_to_ipv6($ip);
312
}
313
314
/**
315
 * Generate a URL friendly slug from the given string.
316
 *
317
 * @param string $string
318
 * @param string $glue
319
 * @return string
320
 */
321
function str_slug($string, $glue = '-')
322
{
323
    return jasny\str_slug($string, $glue);
324
}
325
326
/**
327
 * Replace characters with accents with normal characters.
328
 *
329
 * @param string $string
330
 * @return string
331
 */
332
function str_remove_accents($string)
333
{
334
    return jasny\str_remove_accents($string);
335
}
336
337
/**
338
 * Get the string after the first occurence of the substring.
339
 * If the substring is not found, an empty string is returned.
340
 *
341
 * @param string $string
342
 * @param string $substr
343
 * @return string
344
 */
345
function str_after($string, $substr)
346
{
347
    return jasny\str_after($string, $substr);
348
}
349
350
/**
351
 * Get the string before the first occurence of the substring.
352
 * If the substring is not found, the whole string is returned.
353
 *
354
 * @param string $string
355
 * @param string $substr
356
 * @return string
357
 */
358
function str_before($string, $substr)
359
{
360
    return jasny\str_before($string, $substr);
361
}
362
363
/**
364
 * Check if a string contains a substring
365
 *
366
 * @param string $string
367
 * @param string $substr
368
 * @return bool
369
 */
370
function str_contains($string, $substr)
371
{
372
    return jasny\str_contains($string, $substr);
373
}
374
375
/**
376
 * Check if a string ends with a substring
377
 *
378
 * @param string $string
379
 * @param string $substr
380
 * @return bool
381
 */
382
function str_ends_with($string, $substr)
383
{
384
    return jasny\str_ends_with($string, $substr);
385
}
386
387
/**
388
 * Check if a string starts with a substring
389
 *
390
 * @param string $string
391
 * @param string $substr
392
 * @return bool
393
 */
394
function str_starts_with($string, $substr)
395
{
396
    return jasny\str_starts_with($string, $substr);
397
}
398
399
/**
400
 * Check that an argument has a specific type, otherwise throw an exception.
401
 *
402
 * @param mixed           $var
403
 * @param string|string[] $type
404
 * @param string          $throwable  Class name
405
 * @param string          $message
406
 * @return void
407
 * @throws \InvalidArgumentException
408
 */
409
function expect_type($var, $type, $throwable = 'TypeError', $message = NULL)
410
{
411
    return jasny\expect_type($var, $type, $throwable, $message);
0 ignored issues
show
Bug introduced by
Are you sure the usage of expect_type($var, $type, $throwable, $message) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
412
}
413
414
/**
415
 * Turn stdClass object into associated array recursively.
416
 *
417
 * @param \stdClass|mixed $var
418
 * @return array|mixed
419
 */
420
function arrayify($var)
421
{
422
    return jasny\arrayify($var);
423
}
424
425
/**
426
 * Turn associated array into stdClass object recursively.
427
 *
428
 * @param array|mixed $var
429
 * @return \stdClass|mixed
430
 */
431
function objectify($var)
432
{
433
    return jasny\objectify($var);
434
}
435
436
/**
437
 * Check if variable is a numeric array.
438
 *
439
 * @param array|mixed $var
440
 * @return bool
441
 */
442
function is_numeric_array($var)
443
{
444
    return jasny\is_numeric_array($var);
445
}
446
447
/**
448
 * Check if variable is an associative array.
449
 *
450
 * @param array|mixed $var
451
 * @return bool
452
 */
453
function is_associative_array($var)
454
{
455
    return jasny\is_associative_array($var);
456
}
457