Completed
Push — master ( 52a040...d0dd7a )
by Sebastian
04:05
created

Info::setLinks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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