Passed
Push — master ( d2184e...ee1eb5 )
by Sebastian
04:46
created

Key   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 126
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0
wmc 15

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getMacro() 0 3 1
A isNameVariable() 0 3 1
A isDateVariable() 0 3 1
A isMacro() 0 3 2
A getSort() 0 3 1
A setRangePart() 0 3 1
A getRangePart() 0 3 1
A getVariable() 0 3 1
A isNumberVariable() 0 3 1
A __construct() 0 14 5
1
<?php
2
/*
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
 * citeproc-php
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Style\Sort;
11
use Seboettg\CiteProc\CiteProc;
12
use Seboettg\CiteProc\Util\Variables;
13
14
15
/**
16
 * Class Key
17
 *
18
 * The cs:sort element must contain one or more cs:key child elements. The sort key, set as an attribute on cs:key, must
19
 * be a variable (see Appendix IV - Variables) or macro name. For each cs:key element, the sort direction can be set to
20
 * either “ascending” (default) or “descending” with the sort attribute. The attributes names-min, names-use-first, and
21
 * names-use-last may be used to override the values of the corresponding et-al-min/et-al-subsequent-min,
22
 * et-al-use-first/et-al-subsequent-use-first and et-al-use-last attributes, and affect all names generated via macros
23
 * called by cs:key.
24
 *
25
 * @package Seboettg\CiteProc\Style\Sort
26
 *
27
 * @author Sebastian Böttger <[email protected]>
28
 */
3 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
29
class Key implements SortKey
30
{
31
    /**
32
     * variable name or macro
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
33
     * @var string
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
34
     */
35
    private $variable;
0 ignored issues
show
Coding Style introduced by
Private member variable "variable" must be prefixed with an underscore
Loading history...
36
37
    /**
38
     * the sort direction can be set to either “ascending” (default) or “descending” with the sort attribute
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
39
     * @var string
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
40
     */
41
    private $sort = "ascending";
0 ignored issues
show
Coding Style introduced by
Private member variable "sort" must be prefixed with an underscore
Loading history...
42
43
    /**
44
     * macro name
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
45
     * @var string
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
46
     */
47
    private $macro;
0 ignored issues
show
Coding Style introduced by
Private member variable "macro" must be prefixed with an underscore
Loading history...
48
49
    /**
50
     * only relevant for date ranges
0 ignored issues
show
Coding Style introduced by
Doc comment short description must start with a capital letter
Loading history...
51
     * @var int
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
52
     */
53
    private $rangePart = 1;
0 ignored issues
show
Coding Style introduced by
Private member variable "rangePart" must be prefixed with an underscore
Loading history...
54
55
    /**
56
     * Key constructor.
57
     * The cs:sort element must contain one or more cs:key child elements. The sort key, set as an attribute on cs:key,
58
     * must be a variable (see Appendix IV - Variables) or macro name. For each cs:key element, the sort direction can
59
     * be set to either “ascending” (default) or “descending” with the sort attribute.
60
     *
61
     * TODO: The attributes names-min, names-use-first, and names-use-last may be used to override the values of the
62
     * corresponding et-al-min/et-al-subsequent-min, et-al-use-first/et-al-subsequent-use-first and et-al-use-last
63
     * attributes, and affect all names generated via macros called by cs:key.
64
     *
65
     * @param \SimpleXMLElement $node
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
66
     */
67 44
    public function __construct(\SimpleXMLElement $node)
68
    {
69
        /** @var \SimpleXMLElement $attribute */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
70 44
        foreach ($node->attributes() as $attribute) {
71 44
            $name = $attribute->getName();
72 44
            if ($name === "variable") {
73 29
                $this->variable = (string) $attribute;
74
            }
75 44
            if ($name === "sort") {
76 21
                $this->sort = (string) $attribute;
77
            }
78 44
            if ($name === "macro") {
79 29
                $this->variable = "macro";
80 29
                $this->macro = (string) $attribute;
81
            }
82
        }
83 44
    }
84
85
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
     * @return string
87
     */
88 27
    public function getVariable()
89
    {
90 27
        return $this->variable;
91
    }
92
93
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
94
     * @return string (ascending|descending)
95
     */
96 27
    public function getSort()
97
    {
98 27
        return $this->sort;
99
    }
100
101
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
102
     * @return string
103
     */
104 13
    public function getMacro()
105
    {
106 13
        return $this->macro;
107
    }
108
109
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
110
     * @return bool
111
     */
112 27
    public function isNameVariable()
113
    {
114 27
        return Variables::isNameVariable($this->variable);
115
    }
116
117
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
118
     * @return bool
119
     */
120 26
    public function isNumberVariable()
121
    {
122 26
        return Variables::isNumberVariable($this->variable);
123
    }
124
125
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
126
     * @return bool
127
     */
128 27
    public function isDateVariable()
129
    {
130 27
        return Variables::isDateVariable($this->variable);
131
    }
132
133
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
134
     * @return bool
135
     */
136 21
    public function isMacro()
137
    {
138 21
        return $this->variable === "macro" && !empty(CiteProc::getContext()->getMacro($this->macro));
139
    }
140
141
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $rangePart should have a doc-comment as per coding-style.
Loading history...
142
     * @param $rangePart
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
143
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
144 1
    public function setRangePart($rangePart)
145
    {
146 1
        $this->rangePart = $rangePart;
147 1
    }
148
149
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
150
     * @return int
151
     */
152 5
    public function getRangePart()
153
    {
154 5
        return $this->rangePart;
155
    }
156
}