Completed
Push — master ( 72d645...a1ccb9 )
by Mr
03:56 queued 41s
created

ArrayHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkIfKeysNotExist() 0 10 5
A checkIfKeyNotExist() 0 4 1
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 keys in array
15
     *
16
     * @param   array $keys
17
     * @param   array $array
18
     * @return  string|bool Return true if all fine, and string with name of key which was not found
19
     */
20 5
    public static function checkIfKeysNotExist(array $keys, array $array)
21
    {
22 5
        $output = [];
23 5
        foreach ($keys as $key) {
24 5
            if (!array_key_exists($key, $array) && isset($array[$key])) {
25 5
                $output[] = $key;
26
            }
27
        }
28 5
        return !empty($output) ? implode(',', $output) : true;
29
    }
30
31
    /**
32
     * Check if key in list of parameters
33
     *
34
     * @param   string $key
35
     * @param   array  $array
36
     * @return  bool
37
     */
38 13
    public static function checkIfKeyNotExist(string $key, array $array): bool
39
    {
40 13
        return (!array_key_exists($key, $array));
41
    }
42
}
43