Passed
Push — develop ( 0de06e...665f09 )
by Sebastian
02:06 queued 12s
created

Locator::mapLocatorLabelToRenderVariable()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 4
nop 1
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 3.072
rs 10
c 1
b 0
f 0
1
<?php
2
/*
3
 * citeproc-php: Locator.php
4
 * User: Sebastian Böttger <[email protected]>
5
 * created at 08.04.20, 15:21
6
 */
7
8
namespace Seboettg\CiteProc\Terms;
9
10
use MyCLabs\Enum\Enum;
11
12
class Locator extends Enum
13
{
14
    const BOOK = "book";
15
    const CHAPTER = "chapter";
16
    const COLUMN = "column";
17
    const FIGURE = "figure";
18
    const FOLIO = "folio";
19
    const ISSUE = "issue";
20
    const LINE = "line";
21
    const NOTE = "note";
22
    const OPUS = "opus";
23
    const PAGE = "page";
24
    const PARAGRAPH = "paragraph";
25
    const PART = "part";
26
    const SECTION = "section";
27
    const SUB_VERBO = "sub-verbo";
28
    const VERSE = "verse";
29
    const VOLUME = "volume";
30
31
    private const LABEL_TO_VARIABLE_MAP = [
32
        "chapter" => "chapter-number",
33
    ];
34
35
    /**
36
     * @param string|Locator $locatorTerm
37
     * @return string
38
     */
39 4
    public static function mapLocatorLabelToRenderVariable($locatorTerm)
40
    {
41 4
        if ($locatorTerm instanceof Locator) {
42
            $locatorTerm = (string)$locatorTerm;
43
        }
44
        return
45 4
            array_key_exists($locatorTerm, self::LABEL_TO_VARIABLE_MAP) ?
46 4
                self::LABEL_TO_VARIABLE_MAP[$locatorTerm] : $locatorTerm;
47
    }
48
}
49