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

K10plusMetadata   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 63
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPublicationType() 0 4 1
A getPersons() 0 23 3
A getTitle() 0 17 3
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
 * K10plusMetadata
19
 */
20
class K10plusMetadata extends ExternalMetadata
21
{
22
    public function getTitle(): string
23
    {
24
        $node = $this->getDataXpath()->query('/mods:mods/mods:titleInfo[1]/mods:title[1]');
25
26
        $title = '';
27
28
        if ($node->length == 1) {
29
            $title .= $node->item(0)->nodeValue;
30
        }
31
32
        $node = $this->getDataXpath()->query('/mods:mods/mods:titleInfo[1]/mods:subTitle[1]');
33
34
        if ($node->length == 1) {
35
            $title .= " - ".$node->item(0)->nodeValue;
36
        }
37
38
        return $title;
39
    }
40
41
    public function getPersons(): array
42
    {
43
        $xpath = $this->getDataXpath();
44
45
        $personList = [];
46
47
        $nodes = $xpath->query('/mods:mods/mods:name[@type="personal"]');
48
49
        foreach ($nodes as $person) {
50
51
            $name = ['family' => '', 'given' => ''];
52
53
            $namePartNodes =  $xpath->query('mods:namePart', $person);
54
55
            if ($namePartNodes->length > 0) {
56
57
                list($name['family'], $name['given']) = explode(',', $namePartNodes->item(0)->nodeValue);
58
59
                $personList[] = $name;
60
            }
61
        }
62
63
        return $personList;
64
    }
65
66
    public function getYear(): string
67
    {
68
        $xpath = $this->getDataXpath();
69
70
        $node = $xpath->query('/mods:mods/mods:originInfo/mods:dateIssued');
71
72
        if ($node->length > 0) {
73
            return $node->item(0)->nodeValue;
74
        }
75
76
        return '';
77
    }
78
79
    public function getPublicationType(): string
80
    {
81
        // The k10 plus catalog has no usable document type for the purpose of importing into kitodo.
82
        return '';
83
    }
84
85
}
86