Passed
Pull Request — master (#195)
by
unknown
17:55
created

CrossRefMetadata   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 9 2
A getPublicationType() 0 9 2
A getPersons() 0 26 4
A getYear() 0 11 2
1
<?php
2
namespace EWW\Dpf\Domain\Model;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
/**
18
 * CrossRefMetadata
19
 */
20
class CrossRefMetadata extends ExternalMetadata
21
{
22
23
    /**
24
     * @return string
25
     * @throws \Exception
26
     */
27
    public function getTitle(): string
28
    {
29
        $node = $this->getDataXpath()->query('/response/message/title');
30
31
        if ($node->length == 1) {
32
            return $node->item(0)->nodeValue;
33
        }
34
35
        return '';
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function getPersons(): array
42
    {
43
        $xpath = $this->getDataXpath();
44
45
        $personList = [];
46
47
        $nodes = $xpath->query('/response/message/author');
48
49
        foreach ($nodes as $person) {
50
51
            $name = ['family' => '', 'given' => ''];
52
53
            $family =  $xpath->query('family', $person);
54
            if ($family->length > 0) {
55
                $name['family'] = $family->item(0)->nodeValue;
56
            }
57
58
            $given =  $xpath->query('given', $person);
59
            if ($given->length > 0) {
60
                $name['given'] = $given->item(0)->nodeValue;
61
            }
62
63
            $personList[] = $name;
64
        }
65
66
        return $personList;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getYear(): string
73
    {
74
        $xpath = $this->getDataXpath();
75
76
        $node = $xpath->query('/response/message/created/date-parts/item[@key="0"]');
77
78
        if ($node->length == 1) {
79
            return $node->item(0)->nodeValue;
80
        }
81
82
        return '';
83
    }
84
85
    /**
86
     * @return string
87
     * @throws \Exception
88
     */
89
    public function getPublicationType(): string
90
    {
91
        $node = $this->getDataXpath()->query('/response/message/type');
92
93
        if ($node->length == 1) {
94
            return $node->item(0)->nodeValue;
95
        }
96
97
        return '';
98
    }
99
100
}
101