EutilsEfetch   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 42
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequestOptions() 0 5 1
A getDataFrom() 0 9 2
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