Completed
Pull Request — master (#41)
by
unknown
04:09
created

ArrayHelper::checkIfKeysNotExist()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.9332
c 0
b 0
f 0
cc 4
nc 6
nop 2
crap 20
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
     *
19
     * @return bool
20
     */
21
    public static function checkIfKeyNotExist(string $key, array $array): bool
22
    {
23
        return (!array_key_exists($key, $array) && empty($array[$key]));
24
    }
25
26
    /**
27
     * Check if required keys in array of parameters
28
     *
29
     * @param array $keys
30
     * @param array $array
31
     *
32
     * @return array|bool Return true if all fine, and string with name of key which was not found
33
     */
34
    public static function checkIfKeysNotExist(array $keys, array $array)
35
    {
36
        $output = [];
37
        foreach ($keys as $key) {
38
            if (self::checkIfKeyNotExist($key, $array)) {
39
                $output[] = $key;
40
            }
41
        }
42
        return !empty($output) ? implode(',', $output) : true;
43
    }
44
}
45