Passed
Pull Request — master (#195)
by
unknown
07:20
created

DataCiteMetadata   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 64
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
 * DataCiteMetadata
19
 */
20
class DataCiteMetadata extends ExternalMetadata
21
{
22
    public function getTitle(): string
23
    {
24
        $node = $this->getDataXpath()->query('/response/data/attributes/titles/title');
25
26
        if ($node->length == 1) {
27
            return $node->item(0)->nodeValue;
28
        }
29
30
        return '';
31
    }
32
33
    public function getPersons(): array
34
    {
35
        $xpath = $this->getDataXpath();
36
37
        $personList = [];
38
39
        $nodes = $xpath->query('/response/data/attributes/creators');
40
41
        foreach ($nodes as $person) {
42
43
            $name = ['family' => '', 'given' => ''];
44
45
            $family = $xpath->query('familyName', $person);
46
            if ($family->length > 0) {
47
                $name['family'] = $family->item(0)->nodeValue;
48
            }
49
50
            $given =  $xpath->query('givenName', $person);
51
            if ($given->length > 0) {
52
                $name['given'] = $given->item(0)->nodeValue;
53
            }
54
55
            $personList[] = $name;
56
        }
57
58
        return $personList;
59
60
    }
61
62
    public function getYear(): string
63
    {
64
        $xpath = $this->getDataXpath();
65
66
        $node = $xpath->query('/response/data/attributes/publicationYear');
67
68
        if ($node->length == 1) {
69
            return $node->item(0)->nodeValue;
70
        }
71
72
        return '';
73
    }
74
75
    public function getPublicationType(): string
76
    {
77
        $node = $this->getDataXpath()->query('/response/data/attributes/types/resourceTypeGeneral');
78
79
        if ($node->length == 1) {
80
            return $node->item(0)->nodeValue;
81
        }
82
83
        return '';
84
    }
85
86
}
87