Hashee   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 0
dl 0
loc 80
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A addBulk() 0 4 1
A delete() 0 4 1
A in() 0 4 1
A deleteBulk() 0 8 3
A release() 0 7 2
1
<?php namespace Serima\Hashee;
2
3
class Hashee
4
{
5
    /**
6
     * Add a value as hash
7
     *
8
     * @param array $array
9
     * @param $value
10
     * @return void
11
     */
12 2
    public static function add(array &$array, $value)
13
    {
14 2
        $array[$value] = true;
15 2
    }
16
17
    /**
18
     * Add values in bulk as hash
19
     *
20
     * @param array $values
21
     * @return void
22
     */
23 3
    public static function addBulk(array &$values)
24
    {
25 3
        $values = array_fill_keys($values, true);
26 3
    }
27
28
29
    /**
30
     * Unset the specified value from a hash
31
     *
32
     * @param $array
33
     * @param $value
34
     * @return void
35
     */
36 1
    public static function delete(array &$array, $value)
37
    {
38 1
        unset($array[$value]);
39 1
    }
40
41
    /**
42
     * Unset the specified values in bulk from a hash
43
     *
44
     * @param array $array
45
     * @param array $values
46
     * @return void
47
     */
48 1
    public static function deleteBulk(array &$array, array $values)
49
    {
50 1
        foreach ($values as $value) {
51 1
            if (isset($array[$value])) {
52 1
                unset($array[$value]);
53
            }
54
        }
55 1
    }
56
57
    /**
58
     * Checks if a value exists in a hash
59
     *
60
     * @param string $needle
61
     * @param array $haystack
62
     * @return bool
63
     */
64 3
    public static function in($needle, array $haystack)
65
    {
66 3
        return isset($haystack[$needle]);
67
    }
68
69
    /**
70
     * Unset a hash
71
     *
72
     * @param array $array
73
     * @return void
74
     */
75 1
    public static function release(array &$array)
76
    {
77 1
        $keys = array_keys($array);
78 1
        foreach ($keys as $k) {
79 1
            unset($array[$k]);
80
        }
81
    }
82
}