Passed
Push — master ( 6ba3d6...287c0c )
by Xavier
05:28
created

Arxiv::extract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 1
eloc 7
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources\Extractors;
4
5
class Arxiv extends Extractor implements ProvidesPublicationData, ProvidesIdentifiersData, ProvidesAuthorsData, ProvidesJournalData, ProvidesTypesData
6
{
7
    /**
8
     * Create search tree.
9
     */
10
    protected function getDataFromDocument()
11
    {
12
        $this->searchTree = $this->document->entry;
13
    }
14
15 4
    /**
16
     * Extract and format data needed for the Publication Model.
17 4
     */
18 4
    public function extractPublicationData()
19
    {
20 4
        $this->output['publication'] = [
21
            'title' => get_string($this->searchTree, 'title'),
22 4
            'abstract' => get_string($this->searchTree, 'summary'),
23
            'url' => get_string($this->searchTree, 'id'),
24 4
            'published_at' => date_from_parseable_format(get_string($this->searchTree, 'published')),
25 4
        ];
26 4
    }
27 4
28 4
    /**
29
     * Extract and format data needed for the Identifiers Relationship
30 4
     * on the Publication Model.
31
     */
32
    public function extractIdentifiersData()
33 4
    {
34
        $this->output['identifiers'][] = [
35 4
            'value' => (string) $this->getIdentifier(),
36 4
            'type' => 'arxiv',
37
        ];
38
39
        $this->output['identifiers'][] = [
40
            'value' => '2331-8422',
41 4
            'type' => 'issn',
42
        ];
43 4
    }
44 4
45 4
    /**
46 4
     * Extract and format data needed for the Journals Relationship
47 4
     * on the Publication Model.
48
     */
49 4
    public function extractJournalData()
50
    {
51
        $this->output['journal'] = [
52
            'title' => 'arXiv',
53
            'issn' => ['2331-8422'],
54
        ];
55 4
    }
56
57 4
    /**
58 4
     * Extract and format data needed for the Authors Relationship
59 4
     * on the Publication Model.
60
     */
61
    public function extractAuthorsData()
62 4
    {
63
        foreach (get_array($this->searchTree, 'author') as $author) {
64
            $name = explode(' ', $author->name, 2);
65
            $this->output['authors'][] = [
66 4
                'first_name' => $name[0] ?? null,
67
                'last_name' => $name[1] ?? null,
68
            ];
69
        }
70
    }
71
72 4
    /**
73
     * Extract and format data needed for the Types Relationship
74 4
     * on the Publication Model.
75
     */
76
    public function extractTypesData()
77
    {
78 4
        $this->output['types'][] = [
79
            'name' => 'arxiv',
80
        ];
81
    }
82
83
    /**
84 4
     * @return mixed
85
     */
86 4
    protected function getIdentifier()
87 4
    {
88 4
        $urlParts = explode('/', $this->searchTree->id[0]);
89 4
90 4
        return array_pop($urlParts);
91
    }
92
}
93