ReferenceMap   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addReference() 0 5 1
A contains() 0 6 1
A getReference() 0 10 2
A listReferences() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Reference;
16
17
/**
18
 * A collection of references, indexed by label
19
 */
20
final class ReferenceMap implements ReferenceMapInterface
21
{
22
    /**
23
     * @var ReferenceInterface[]
24
     */
25
    protected $references = [];
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 246
    public function addReference(ReferenceInterface $reference): void
31
    {
32 246
        $key = Reference::normalizeReference($reference->getLabel());
33 246
        $this->references[$key] = $reference;
34 246
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 243
    public function contains(string $label): bool
40
    {
41 243
        $label = Reference::normalizeReference($label);
42
43 243
        return isset($this->references[$label]);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 294
    public function getReference(string $label): ?ReferenceInterface
50
    {
51 294
        $label = Reference::normalizeReference($label);
52
53 294
        if (!isset($this->references[$label])) {
54 111
            return null;
55
        }
56
57 204
        return $this->references[$label];
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 6
    public function listReferences(): iterable
64
    {
65 6
        return \array_values($this->references);
66
    }
67
}
68