Passed
Push — new-api ( 18d26d...074931 )
by Sebastian
04:59
created

GlobalOptions::getDemoteNonDroppingParticle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
/*
4
 * citeproc-php
5
 *
6
 * @link        http://github.com/seboettg/citeproc-php for the source repository
7
 * @copyright   Copyright (c) 2017 Sebastian Böttger.
8
 * @license     https://opensource.org/licenses/MIT
9
 */
10
11
namespace Seboettg\CiteProc\Style\Options;
12
13
use SimpleXMLElement;
14
15
/**
16
 * Class GlobalOptionsTrait
17
 * @package Seboettg\CiteProc\Style
18
 * @author Sebastian Böttger <[email protected]>
19
 */
20
class GlobalOptions
21
{
22
    /** @var bool */
23
    private $initializeWithHyphen;
24
25
    /** @var PageRangeFormats */
26
    private $pageRangeFormats;
27
28
    /** @var DemoteNonDroppingParticle */
29
    private $demoteNonDroppingParticle;
30
31 173
    public static function factory(SimpleXMLElement $node): GlobalOptions
32
    {
33 173
        $initializeWithHyphen = true;
34 173
        $pageRangeFormats = null;
35 173
        $demoteNonDroppingParticle = null;
36
37
        /** @var SimpleXMLElement $attribute */
38 173
        foreach ($node->attributes() as $attribute) {
39 170
            switch ($attribute->getName()) {
40 170
                case 'initialize-with-hyphen':
41 2
                    $initializeWithHyphen = "false" === (string) $attribute ? false : true;
42 2
                    break;
43 170
                case 'page-range-format':
44 26
                    $pageRangeFormats = new PageRangeFormats((string) $attribute);
45 26
                    break;
46 170
                case 'demote-non-dropping-particle':
47 170
                    $demoteNonDroppingParticle = new DemoteNonDroppingParticle((string) $attribute);
48
            }
49
        }
50 173
        return new GlobalOptions($initializeWithHyphen, $pageRangeFormats, $demoteNonDroppingParticle);
51
    }
52
53
    /**
54
     * GlobalOptions constructor.
55
     * @param bool $initializeWithHyphen
56
     * @param ?PageRangeFormats $pageRangeFormats
57
     * @param ?DemoteNonDroppingParticle $demoteNonDroppingParticle
58
     */
59 173
    public function __construct(
60
        bool $initializeWithHyphen,
61
        ?PageRangeFormats $pageRangeFormats,
62
        ?DemoteNonDroppingParticle $demoteNonDroppingParticle
63
    ) {
64 173
        $this->initializeWithHyphen = $initializeWithHyphen;
65 173
        $this->pageRangeFormats = $pageRangeFormats;
66 173
        $this->demoteNonDroppingParticle = $demoteNonDroppingParticle;
67 173
    }
68
69
    /**
70
     * Specifies whether compound given names (e.g. “Jean-Luc”) should be initialized with a hyphen (“J.-L.”, value
71
     * “true”, default) or without (“J.L.”, value “false”).
72
     * @return bool
73
     */
74 34
    public function isInitializeWithHyphen(): bool
75
    {
76 34
        return $this->initializeWithHyphen;
77
    }
78
79
    /**
80
     * Activates expansion or collapsing of page ranges: “chicago” (“321–28”), “expanded” (e.g. “321–328”),
81
     * “minimal” (“321–8”), or “minimal-two” (“321–28”). Delimits page ranges
82
     * with the “page-range-delimiter” term (introduced with CSL 1.0.1, and defaults to an en-dash). If the attribute is
83
     * not set, page ranges are rendered without reformatting.
84
     * @return PageRangeFormats
85
     */
86 21
    public function getPageRangeFormats(): ?PageRangeFormats
87
    {
88 21
        return $this->pageRangeFormats;
89
    }
90
91
    /**
92
     * Sets the display and sorting behavior of the non-dropping-particle in inverted names (e.g. “Koning, W. de”).
93
     * @return DemoteNonDroppingParticle
94
     */
95 105
    public function getDemoteNonDroppingParticle(): ?DemoteNonDroppingParticle
96
    {
97 105
        return $this->demoteNonDroppingParticle;
98
    }
99
}
100