Arxiv::getDataFrom()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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