EutilsEfetch::getRequestOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
c 0
b 0
f 0
rs 10
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources;
4
5
use SimpleXMLElement;
6
7
class EutilsEfetch extends Resource
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $url = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi';
13
14
    /**
15
     * @var array
16
     */
17
    protected $queryStringParameters = [
18
        'query' => [
19
            'db' => 'pubmed',
20
            'version' => '2.0',
21
            'retmode' => 'xml',
22
            'id' => '',
23
        ],
24
    ];
25 2
26
    /**
27 2
     * @return array
28 2
     */
29
    public function getRequestOptions(): array
30
    {
31
        $this->queryStringParameters['query']['id'] = $this->identifier->getQueryString();
32
33 1
        return $this->queryStringParameters;
34
    }
35 1
36
    /**
37
     * @param  string  $document
38
     * @return array
39
     */
40
    public function getDataFrom(string $document): array
41 1
    {
42
        try {
43 1
            $baseTree = new SimpleXMLElement($document);
44
            $extractor = new Extractors\EutilsEfetch($baseTree, $this->output);
45
46
            return $extractor->extract();
47
        } catch (\Exception $e) {
48
            return [];
49
        }
50
    }
51
}
52