DoubleKeyMap   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Test Coverage

Coverage 10.34%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 95
ccs 3
cts 29
cp 0.1034
rs 10
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A values() 0 9 2
A getByOneKey() 0 3 1
A getByTwoKeys() 0 9 2
A primaryKeys() 0 3 1
A set() 0 11 2
A secondaryKeys() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Antlr\Antlr4\Runtime\Utils;
6
7
final class DoubleKeyMap
8
{
9
    /**
10
     * Map<primaryKey, Map<secondaryKey, value>>
11
     *
12
     * @var Map
13
     */
14
    private $data;
15
16 3
    public function __construct()
17
    {
18 3
        $this->data = new Map();
19 3
    }
20
21
    /**
22
     * @param mixed $primaryKey
23
     * @param mixed $secondaryKey
24
     * @param mixed $value
25
     */
26
    public function set($primaryKey, $secondaryKey, $value) : void
27
    {
28
        $secondaryData = $this->data->get($primaryKey);
29
30
        if ($secondaryData === null) {
31
            $secondaryData = new Map();
32
33
            $this->data->put($primaryKey, $secondaryData);
34
        }
35
36
        $secondaryData->put($secondaryKey, $value);
37
    }
38
39
    /**
40
     * @param mixed $primaryKey
41
     * @param mixed $secondaryKey
42
     *
43
     * @return mixed
44
     */
45
    public function getByTwoKeys($primaryKey, $secondaryKey)
46
    {
47
        $data2 = $this->data->get($primaryKey);
48
49
        if ($data2 === null) {
50
            return null;
51
        }
52
53
        return $data2->get($secondaryKey);
54
    }
55
56
    /**
57
     * @param mixed $primaryKey
58
     */
59
    public function getByOneKey($primaryKey) : Map
60
    {
61
        return $this->data->get($primaryKey);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data->get($primaryKey) could return the type null which is incompatible with the type-hinted return Antlr\Antlr4\Runtime\Utils\Map. Consider adding an additional type-check to rule them out.
Loading history...
62
    }
63
64
    /**
65
     * @param mixed $primaryKey
66
     *
67
     * @return array<mixed>|null
68
     */
69
    public function values($primaryKey) : ?array
70
    {
71
        $secondaryData = $this->data->get($primaryKey);
72
73
        if ($secondaryData === null) {
74
            return null;
75
        }
76
77
        return $secondaryData->getValues();
78
    }
79
80
    /**
81
     * @return array<mixed>
82
     */
83
    public function primaryKeys() : array
84
    {
85
        return $this->data->getKeys();
86
    }
87
88
    /**
89
     * @param mixed $primaryKey
90
     *
91
     * @return array<mixed>|null
92
     */
93
    public function secondaryKeys($primaryKey) : ?array
94
    {
95
        $secondaryData = $this->data->get($primaryKey);
96
97
        if ($secondaryData === null) {
98
            return null;
99
        }
100
101
        return $secondaryData->getKeys();
102
    }
103
}
104