Completed
Push — master ( 5c6970...94a889 )
by Sebastian
02:32
created

getSubsequentAuthorSubstituteRule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2017 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Style\Options;
11
12
/**
13
 * Class GlobalOptionsTrait
14
 * @package Seboettg\CiteProc\Style
15
 * @author Sebastian Böttger <[email protected]>
16
 */
17
class BibliographyOptions
18
{
19
20
    /**
21
     * If set, the value of this attribute replaces names in a bibliographic entry that also occur in the preceding
22
     * entry. The exact method of substitution depends on the value of the subsequent-author-substitute-rule attribute.
23
     * Substitution is limited to the names of the first cs:names element rendered. (Bibliography-specific option)
24
     *
25
     * @var string
26
     */
27
    private $subsequentAuthorSubstitute;
28
29
    /**
30
     * Specifies when and how names are substituted as a result of subsequent-author-substitute.
31
     * (Bibliography-specific option)
32
     *
33
     * @var SubsequentAuthorSubstituteRule
34
     */
35
    private $subsequentAuthorSubstituteRule;
36
37
    /**
38
     * If set to “true” (“false” is the default), bibliographic entries are rendered with hanging-indents.
39
     * @var string
40
     */
41
    private $hangingIndent = false;
42
43
    /**
44
     * If set, subsequent lines of bibliographic entries are aligned along the second field. With “flush”, the first
45
     * field is flush with the margin. With “margin”, the first field is put in the margin, and subsequent lines are
46
     * aligned with the margin.
47
     * @var string
48
     */
49
    private $secondFieldAlign;
50
51
    /**
52
     * Specifies vertical line distance. Defaults to “1” (single-spacing), and can be set to any positive integer to
53
     * specify a multiple of the standard unit of line height (e.g. “2” for double-spacing).
54
     * @var string
55
     */
56
    private $lineSpacing;
57
58
    /**
59
     * Specifies vertical distance between bibliographic entries. By default (with a value of “1”), entries are
60
     * separated by a single additional line-height (as set by the line-spacing attribute). Can be set to any
61
     * non-negative integer to specify a multiple of this amount.
62
     * @var string
63
     */
64
    private $entrySpacing;
65
66
    public function __construct(\SimpleXMLElement $node)
67
    {
68
69
        /** @var \SimpleXMLElement $attribute */
70
        foreach ($node->attributes() as $attribute) {
71
            switch ($attribute->getName()) {
72
                case 'subsequent-author-substitute':
73
                    $this->subsequentAuthorSubstitute = (string) $attribute;
74
                    break;
75
                case 'subsequent-author-substitute-rule':
76
                    $this->subsequentAuthorSubstituteRule = new SubsequentAuthorSubstituteRule((string) $attribute);
77
                    break;
78
                case 'hanging-indent':
79
                    $this->hangingIndent = "true" === (string) $attribute ? true : false;
0 ignored issues
show
Documentation Bug introduced by
The property $hangingIndent was declared of type string, but 'true' === (string) $attribute ? true : false is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
80
                    break;
81
                case 'second-field-align':
82
                    $this->secondFieldAlign = (string) $attribute;
83
                    break;
84
                case 'line-spacing':
85
                    $this->lineSpacing = (string) $attribute;
86
                    break;
87
                case 'entry-spacing':
88
                    $this->entrySpacing = (string) $attribute;
89
            }
90
        }
91
        if (empty($this->subsequentAuthorSubstituteRule)) {
92
            $this->subsequentAuthorSubstituteRule = new SubsequentAuthorSubstituteRule("complete-all");
93
        }
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getSubsequentAuthorSubstitute()
100
    {
101
        return $this->subsequentAuthorSubstitute;
102
    }
103
104
    /**
105
     * @param string $subsequentAuthorSubstitute
106
     */
107
    public function setSubsequentAuthorSubstitute($subsequentAuthorSubstitute)
108
    {
109
        $this->subsequentAuthorSubstitute = $subsequentAuthorSubstitute;
110
    }
111
112
    /**
113
     * @return SubsequentAuthorSubstituteRule
114
     */
115
    public function getSubsequentAuthorSubstituteRule()
116
    {
117
        return $this->subsequentAuthorSubstituteRule;
118
    }
119
120
    /**
121
     * @param SubsequentAuthorSubstituteRule $subsequentAuthorSubstituteRule
122
     */
123
    public function setSubsequentAuthorSubstituteRule($subsequentAuthorSubstituteRule)
124
    {
125
        $this->subsequentAuthorSubstituteRule = $subsequentAuthorSubstituteRule;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function getHangingIndent()
132
    {
133
        return $this->hangingIndent;
134
    }
135
136
    /**
137
     * @param string $hangingIndent
138
     */
139
    public function setHangingIndent($hangingIndent)
140
    {
141
        $this->hangingIndent = $hangingIndent;
142
    }
143
144
    /**
145
     * @return string
146
     */
147
    public function getSecondFieldAlign()
148
    {
149
        return $this->secondFieldAlign;
150
    }
151
152
    /**
153
     * @param string $secondFieldAlign
154
     */
155
    public function setSecondFieldAlign($secondFieldAlign)
156
    {
157
        $this->secondFieldAlign = $secondFieldAlign;
158
    }
159
160
    /**
161
     * @return string
162
     */
163
    public function getLineSpacing()
164
    {
165
        return $this->lineSpacing;
166
    }
167
168
    /**
169
     * @param string $lineSpacing
170
     */
171
    public function setLineSpacing($lineSpacing)
172
    {
173
        $this->lineSpacing = $lineSpacing;
174
    }
175
176
    /**
177
     * @return string
178
     */
179
    public function getEntrySpacing()
180
    {
181
        return $this->entrySpacing;
182
    }
183
184
    /**
185
     * @param string $entrySpacing
186
     */
187
    public function setEntrySpacing($entrySpacing)
188
    {
189
        $this->entrySpacing = $entrySpacing;
190
    }
191
192
193
}