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

CrossrefUpdates   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extractUpdatesData() 0 9 2
A fillSearchTree() 0 11 3
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