Completed
Push — master ( e36bb3...7a84ca )
by Derek
02:12
created

ArrayHelper::valueLookup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
namespace Subreality\Dilmun\Anshar\Utils;
3
4
5
class ArrayHelper
6
{
7
    /** @var  array */
8
    protected $array;
9
10
    /**
11
     * ArrayHelper constructor.  Accepts and stores an array.
12
     *
13
     * @throws \InvalidArgumentException    if not initialized with an array
14
     * @param mixed[] $array                The array needing help
15
     */
16 7
    public function __construct($array)
17
    {
18 7
        if (!is_array($array)) {
19 6
            throw new \InvalidArgumentException("Supplied array is not an array");
20
        }
21
22 1
        $this->array = $array;
23 1
    }
24
25
    /**
26
     * Returns the value corresponding with a supplied key; returns FALSE if the supplied key does not exist within
27
     * the array.
28
     *
29
     * **WARNING** This function may return FALSE or a non-Boolean value that evaluates to FALSE even if a supplied
30
     * key exists
31
     *
32
     * @param int|string $key   The key to look up
33
     * @return bool|mixed       Returns FALSE if the supplied key does not exist within the array
34
     *                          Returns the value corresponding with the key otherwise
35
     */
36 2
    public function valueLookup($key)
37
    {
38 2
        $value = false;
39
40 2
        if (array_key_exists($key, $this->array)) {
41 1
            $value = $this->array[$key];
42 1
        }
43
44 2
        return $value;
45
    }
46
}