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

PubmedWebsite   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataFrom() 0 8 2
A getApiUrl() 0 3 1
A __construct() 0 3 1
A getRequestOptions() 0 3 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