CrossrefUpdates   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 12
c 1
b 0
f 1
dl 0
loc 31
rs 10

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\Exceptions\UnparseableApiException;
6
use PubPeerFoundation\PublicationDataExtractor\Support\UpdateTypesStandardiser;
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