KeyBag   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 0
dl 0
loc 59
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 1
A get() 0 8 2
A registerNamespace() 0 4 1
A getNamespaces() 0 4 1
1
<?php
2
3
/*
4
 * (c) Mantas Varatiejus <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace MVar\Apache2LogParser;
11
12
/**
13
 * This is the class that holds temporary keys for preg_match(). It helps
14
 * to convert flat array to multidimensional.
15
 */
16
class KeyBag
17
{
18
    /**
19
     * @var array
20
     */
21
    protected $storage = [];
22
23
    /**
24
     * Stores key to local storage and returns it's index
25
     *
26
     * @param string $namespace
27
     * @param string $key
28
     *
29
     * @return int Stored key index
30
     */
31 3
    public function add($namespace, $key)
32
    {
33 3
        $this->storage[$namespace][] = $key;
34
35 3
        return count($this->storage[$namespace]) - 1;
36
    }
37
38
    /**
39
     * Returns key from local storage
40
     *
41
     * @param string $namespace
42
     * @param int    $index
43
     *
44
     * @return string|null
45
     */
46 3
    public function get($namespace, $index)
47
    {
48 3
        if (!isset($this->storage[$namespace][$index])) {
49 1
            return null;
50
        }
51
52 2
        return $this->storage[$namespace][$index];
53
    }
54
55
    /**
56
     * Registers namespace
57
     *
58
     * @param string $namespace
59
     */
60 1
    public function registerNamespace($namespace)
61
    {
62 1
        $this->storage[$namespace] = [];
63 1
    }
64
65
    /**
66
     * Returns names of all stored namespaces
67
     *
68
     * @return array
69
     */
70 2
    public function getNamespaces()
71
    {
72 2
        return array_keys($this->storage);
73
    }
74
}
75