Passed
Push — master ( 661b73...ccb1dd )
by Sebastian
08:54 queued 05:17
created

NamePart::getName()   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
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Rendering\Name;
11
12
use Seboettg\CiteProc\Exception\CiteProcException;
13
use Seboettg\CiteProc\Styles\AffixesTrait;
14
use Seboettg\CiteProc\Styles\FormattingTrait;
15
use Seboettg\CiteProc\Styles\TextCaseTrait;
16
use SimpleXMLElement;
17
18
/**
19
 * Class NamePart
20
 *
21
 * The cs:name element may contain one or two cs:name-part child elements for name-part-specific formatting.
22
 * cs:name-part must carry the name attribute, set to either “given” or “family”.
23
 *
24
 * If set to “given”, formatting and text-case attributes on cs:name-part affect the “given” and “dropping-particle”
25
 * name-parts. affixes surround the “given” name-part, enclosing any demoted name particles for inverted names.
26
 *
27
 * If set to “family”, formatting and text-case attributes affect the “family” and “non-dropping-particle” name-parts.
28
 * affixes surround the “family” name-part, enclosing any preceding name particles, as well as the “suffix” name-part
29
 * for non-inverted names.
30
 *
31
 * The “suffix” name-part is not subject to name-part formatting. The use of cs:name-part elements does not influence
32
 * which, or in what order, name-parts are rendered.
33
 *
34
 *
35
 * @package Seboettg\CiteProc\Rendering\Name
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
36
 *
37
 * @author Sebastian Böttger <[email protected]>
38
 */
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...
39
class NamePart
40
{
41
42
    use FormattingTrait,
0 ignored issues
show
Bug introduced by
The trait Seboettg\CiteProc\Styles\AffixesTrait requires the property $single which is not provided by Seboettg\CiteProc\Rendering\Name\NamePart.
Loading history...
43
        TextCaseTrait,
44
        AffixesTrait;
45
46
    private $name;
0 ignored issues
show
Coding Style introduced by
Private member variable "name" must be prefixed with an underscore
Loading history...
47
48
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
49
     * @var Name
50
     */
51
    private $parent;
0 ignored issues
show
Coding Style introduced by
Private member variable "parent" must be prefixed with an underscore
Loading history...
52
53
    /**
54
     * NamePart constructor.
55
     * @param SimpleXMLElement $node
2 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
56
     * @param Name $parent
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 13 spaces after parameter type; 1 found
Loading history...
57
     */
58 3
    public function __construct(SimpleXMLElement $node, $parent)
59
    {
60 3
        $this->parent = $parent;
61
62
        /** @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...
63 3
        foreach ($node->attributes() as $attribute) {
64 3
            if ($attribute->getName() === 'name') {
65 3
                $this->name = (string) $attribute;
66
            }
67
        }
68
69 3
        $this->initFormattingAttributes($node);
70 3
        $this->initTextCaseAttributes($node);
71 3
        $this->initAffixesAttributes($node);
72 3
    }
73
74
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
Parameter $data should have a doc-comment as per coding-style.
Loading history...
75
     * @param $data
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
76
     * @return mixed
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
77
     * @throws CiteProcException
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
78
     */
79 2
    public function render($data)
80
    {
81 2
        if (!isset($data->{$this->name})) {
82
            return "";
83
        }
84
85 2
        switch ($this->name) {
86
87
            /* If set to “given”, formatting and text-case attributes on cs:name-part affect the “given” and
88
            “dropping-particle” name-parts. affixes surround the “given” name-part, enclosing any demoted name particles
89
            for inverted names.*/
90 2
            case 'given':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
91 2
                return $this->addAffixes($this->format($this->applyTextCase($data->given)));
92
93
            /* if name set to “family”, formatting and text-case attributes affect the “family” and
94
            “non-dropping-particle” name-parts. affixes surround the “family” name-part, enclosing any preceding name
95
            particles, as well as the “suffix” name-part for non-inverted names.*/
96 2
            case 'family':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
97 2
                return $this->addAffixes($this->format($this->applyTextCase($data->family)));
98
99
        }
100
        throw new CiteProcException("This shouldn't happen.");
101
    }
102
103
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
104
     * @return string
105
     */
106 3
    public function getName()
107
    {
108 3
        return $this->name;
109
    }
110
111
}