Completed
Push — master ( 9497fc...721676 )
by Mr
04:00
created

ArrayHelper::checkIfKeyNotExist()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace RouterOS\Helpers;
4
5
/**
6
 * Class ArrayHelper
7
 *
8
 * @package RouterOS\Helpers
9
 * @since   0.7
10
 */
11
class ArrayHelper
12
{
13
    /**
14
     * Check if required single key in array of parameters
15
     *
16
     * @param   string $key
17
     * @param   array  $array
18
     * @return  bool
19
     */
20 17
    public static function checkIfKeyNotExist(string $key, array $array): bool
21
    {
22 17
        return (!array_key_exists($key, $array) && empty($array[$key]));
23
    }
24
25
    /**
26
     * Check if required keys in array of parameters
27
     *
28
     * @param   array $keys
29
     * @param   array $array
30
     * @return  array|bool Return true if all fine, and string with name of key which was not found
31
     */
32 8
    public static function checkIfKeysNotExist(array $keys, array $array)
33
    {
34 8
        $output = [];
35 8
        foreach ($keys as $key) {
36 8
            if (!array_key_exists($key, $array) && empty($array[$key])) {
37 8
                $output[] = $key;
38
            }
39
        }
40 8
        return !empty($output) ? $output : true;
41
    }
42
}
43