Passed
Branch master (f320c5)
by Xavier
01:33
created

PubmedWebsite::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources;
4
5
use PubPeerFoundation\PublicationDataExtractor\Identifiers\Identifier;
6
7
class PubmedWebsite implements Resource
8
{
9
    protected $url = 'https://www.ncbi.nlm.nih.gov/pubmed/';
10
11
    protected $queryStringParameters = [
12
        'query' => [
13
            'term' => '',
14
        ],
15
    ];
16
17
    protected $input;
18
19
    protected $identifier;
20
21
    public function __construct(Identifier $identifier)
22
    {
23
        $this->queryStringParameters['query']['term'] = $identifier->getQueryString();
24
    }
25
26
    /**
27
     * @return string
28
     */
29
    public function getApiUrl(): string
30
    {
31
        return $this->url;
32
    }
33
34
    /**
35
     * @return array
36
     */
37
    public function getRequestOptions(): array
38
    {
39
        return $this->queryStringParameters;
40
    }
41
42
    /**
43
     * @param string $document
44
     *
45
     * @return array
46
     */
47
    public function getDataFrom(string $document): array
48
    {
49
        try {
50
            $extractor = new Extractors\PubmedWebsite($document);
51
52
            return $extractor->extract();
53
        } catch (\Exception $e) {
54
            return [];
55
        }
56
    }
57
}
58