Completed
Push — master ( 44b4d6...c54f73 )
by WEBEWEB
06:15
created

ArrayHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 2
A set() 0 9 3
1
<?php
2
3
/**
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Helper\Argument;
13
14
/**
15
 * Array helper.
16
 *
17
 * @author webeweb <https://github.com/webeweb/>
18
 * @package WBW\Library\Core\Helper\Argument
19
 */
20
class ArrayHelper {
21
22
    /**
23
     * Get a value.
24
     *
25
     * @param array $array The array.
26
     * @param mixed $key The key.
27
     * @param mixed $default The default value.
28
     * @return mixed Returns the value in case of success, $default otherwise.
29
     */
30
    public static function get(array $array, $key, $default = null) {
31
        return true === array_key_exists($key, $array) ? $array[$key] : $default;
32
    }
33
34
    /**
35
     * Set a value.
36
     *
37
     * @param array $array The array.
38
     * @param string $key The key.
39
     * @param mixed $value The value.
40
     * @param array $tests The tests.
41
     */
42
    public static function set(array &$array, $key, $value, array $tests = []) {
43
        foreach ($tests as $current) {
44
            if ($current !== $value) {
45
                continue;
46
            }
47
            return;
48
        }
49
        $array[$key] = $value;
50
    }
51
52
}
53