Passed
Push — master ( 8360a5...feb138 )
by Xavier
01:22
created

CrossrefUpdates::extractUpdatesData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources\Extractors;
4
5
use PubPeerFoundation\PublicationDataExtractor\Support\UpdateTypesStandardiser;
6
use PubPeerFoundation\PublicationDataExtractor\Exceptions\UnparseableApiException;
7
8
class CrossrefUpdates extends Extractor implements ProvidesUpdatesData
9
{
10
    /**
11
     * @throws UnparseableApiException
12
     */
13
    protected function fillSearchTree(): void
14
    {
15
        if ('ok' !== $this->document['status']) {
16
            throw new UnparseableApiException();
17
        }
18
19
        if (empty($this->document['message']['items'])) {
20
            throw new UnparseableApiException();
21
        }
22
23
        $this->searchTree = $this->document['message']['items'][0];
24
    }
25
26
    /**
27
     * Extract and format data needed for the Updates Relationship
28
     * on the Publication Model.
29
     */
30
    public function extractUpdatesData(): void
31
    {
32
        foreach (get_array($this->searchTree, 'update-to') as $update) {
33
            $this->resourceOutput['updates'][] = [
34
                'timestamp' => $update['updated']['timestamp'],
35
                'identifier' => [
36
                    'doi' => get_string($update, 'DOI'),
37
                ],
38
                'type' => UpdateTypesStandardiser::getType($update['type']),
39
            ];
40
        }
41
    }
42
}
43