Completed
Push — master ( d2636b...e88807 )
by Colin
02:51
created

ReferenceMap   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addReference() 0 7 1
A contains() 0 6 1
A getReference() 0 8 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
class ReferenceMap
21
{
22
    /**
23
     * @var Reference[]
24
     */
25
    protected $references = [];
26
27
    /**
28
     * @param Reference $reference
29
     *
30
     * @return $this
31
     */
32 222
    public function addReference(Reference $reference)
33
    {
34 222
        $key = Reference::normalizeReference($reference->getLabel());
35 222
        $this->references[$key] = $reference;
36
37 222
        return $this;
38
    }
39
40
    /**
41
     * @param string $label
42
     *
43
     * @return bool
44
     */
45 222
    public function contains($label)
46
    {
47 222
        $label = Reference::normalizeReference($label);
48
49 222
        return isset($this->references[$label]);
50
    }
51
52
    /**
53
     * @param string $label
54
     *
55
     * @return Reference|null
56
     */
57 255
    public function getReference($label)
58
    {
59 255
        $label = Reference::normalizeReference($label);
60
61 255
        if (isset($this->references[$label])) {
62 189
            return $this->references[$label];
63
        }
64 87
    }
65
66
    /**
67
     * Lists all registered references.
68
     *
69
     * @return Reference[]
70
     */
71
    public function listReferences()
72
    {
73
        return array_values($this->references);
74
    }
75
}
76