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

ArrayHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 34
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkIfKeyNotExist() 0 4 2
A checkIfKeysNotExist() 0 10 4
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