CrossrefUpdates::getApiUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources;
4
5
use PubPeerFoundation\PublicationDataExtractor\Exceptions\UnparseableApiException;
6
7
class CrossrefUpdates extends Resource
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $url = 'https://api.crossref.org/works?filter=updates:';
13
14
    /**
15
     * @var array
16
     */
17
    protected $queryStringParameters = [
18
        'headers' => [
19
            'User-Agent' => 'PubPeer/2.0 (https://pubpeer.com; mailto:[email protected])',
20
        ],
21
    ];
22
23
    /**
24
     * @var string
25
     */
26
    protected $extractor = Extractors\CrossrefUpdates::class;
27
28
    /**
29
     * @return string
30
     */
31
    public function getApiUrl(): string
32
    {
33
        return $this->url.$this->identifier->getQueryString();
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function getRequestOptions(): array
40
    {
41
        return $this->queryStringParameters;
42
    }
43
44
    /**
45
     * @param  string  $document
46
     * @return array
47
     */
48
    public function getDataFrom(string $document): array
49
    {
50
        $baseTree = json_decode($document, true);
51
52
        if (is_null($baseTree)) {
53
            return [];
54
        }
55
56
        try {
57
            $extractor = new $this->extractor($baseTree, $this->output);
58
59
            return $extractor->extract();
60
        } catch (UnparseableApiException $e) {
61
            return [];
62
        }
63
    }
64
}
65