IdConverter::getRequestOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources;
4
5
class IdConverter extends Resource
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $url = 'https://www.ncbi.nlm.nih.gov/pmc/utils/idconv/v1.0/';
11
12
    /**
13
     * @var array
14
     */
15
    protected $queryStringParameters = [
16
        'query' => [
17
            'format' => 'json',
18
            'tool' => 'pubpeer',
19
            'email' => '[email protected]',
20
            'version' => 'no',
21
            'ids' => '',
22
        ],
23
    ];
24
25
    /**
26
     * @return array
27
     */
28
    public function getRequestOptions(): array
29
    {
30
        $this->queryStringParameters['query']['ids'] = $this->identifier->getQueryString();
31
32
        return $this->queryStringParameters;
33
    }
34
35
    /**
36
     * @param  string  $document
37
     * @return array
38
     */
39
    public function getDataFrom(string $document): array
40
    {
41
        try {
42
            $baseTree = json_decode($document, true);
43
            $extractor = new Extractors\IdConverter($baseTree, $this->output);
44
45
            return $extractor->extract();
46
        } catch (\Exception $e) {
47
            return [];
48
        }
49
    }
50
}
51