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

Reference::normalizeReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 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
 * Link reference
19
 */
20
class Reference
21
{
22
    /**
23
     * @var string
24
     */
25
    protected $label;
26
27
    /**
28
     * @var string
29
     */
30
    protected $destination;
31
32
    /**
33
     * @var string
34
     */
35
    protected $title;
36
37
    /**
38
     * Constructor
39
     *
40
     * @param string $label
41
     * @param string $destination
42
     * @param string $title
43
     */
44 222
    public function __construct($label, $destination, $title)
45
    {
46 222
        $this->label = self::normalizeReference($label);
47 222
        $this->destination = $destination;
48 222
        $this->title = $title;
49 222
    }
50
51
    /**
52
     * @return string
53
     */
54 222
    public function getLabel()
55
    {
56 222
        return $this->label;
57
    }
58
59
    /**
60
     * @return string
61
     */
62 189
    public function getDestination()
63
    {
64 189
        return $this->destination;
65
    }
66
67
    /**
68
     * @return string
69
     */
70 189
    public function getTitle()
71
    {
72 189
        return $this->title;
73
    }
74
75
    /**
76
     * Normalize reference label
77
     *
78
     * This enables case-insensitive label matching
79
     *
80
     * @param string $string
81
     *
82
     * @return string
83
     */
84 285
    public static function normalizeReference($string)
85
    {
86
        // Collapse internal whitespace to single space and remove
87
        // leading/trailing whitespace
88 285
        $string = preg_replace('/\s+/', '', trim($string));
89
90 285
        return mb_strtoupper($string, 'UTF-8');
91
    }
92
}
93