Passed
Push — master ( dcb940...49cd7f )
by Sebastian
14:22 queued 12:58
created

Info::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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\Root;
11
12
use SimpleXMLElement;
13
use stdClass;
14
15
class Info
16
{
17
    /**
18
     * @var string
19
     */
20
    private $title;
21
22
    /**
23
     * @var string
24
     */
25
    private $id;
26
27
    /**
28
     * @var array
29
     */
30
    private $authors;
31
32
    /**
33
     * @var array
34
     */
35
    private $links;
36
37 162
    public function __construct(SimpleXMLElement $node)
38
    {
39 162
        $this->authors = [];
40 162
        $this->links = [];
41
42
        /** @var SimpleXMLElement $child */
43 162
        foreach ($node->children() as $child) {
44 160
            switch ($child->getName()) {
45 160
                case 'author':
46 160
                case 'contributor':
47 42
                    $author = new stdClass();
48
                    /** @var SimpleXMLElement $authorNode */
49 42
                    foreach ($child->children() as $authorNode) {
50 42
                        $author->{$authorNode->getName()} = (string) $authorNode;
51
                    }
52 42
                    $this->authors[] = $author;
53 42
                    break;
54 160
                case 'link':
55 42
                    foreach ($child->attributes() as $attribute) {
56 42
                        if ($attribute->getName() === "value") {
57
                            $this->links[] = (string) $attribute;
58
                        }
59
                    }
60 42
                    break;
61
                default:
62 160
                    $this->{$child->getName()} = (string) $child;
63
            }
64
        }
65 162
    }
66
67
    /**
68
     * @return string
69
     */
70 1
    public function getTitle()
71
    {
72 1
        return $this->title;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getId()
79
    {
80
        return $this->id;
81
    }
82
83
    /**
84
     * @return array
85
     */
86 1
    public function getAuthors()
87
    {
88 1
        return $this->authors;
89
    }
90
91
    /**
92
     * @return array
93
     */
94
    public function getLinks()
95
    {
96
        return $this->links;
97
    }
98
}
99