Passed
Push — master ( 2dbb0d...2ad290 )
by Xavier
01:17
created

EutilsEsearch::fillSearchTree()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources\Extractors;
4
5
use PubPeerFoundation\PublicationDataExtractor\Exceptions\UnparseableApiException;
6
7
class EutilsEsearch extends Extractor implements ProvidesIdentifiersData
8
{
9
    /**
10
     * Extract search tree from document.
11
     *
12
     * @throws UnparseableApiException
13
     */
14
    protected function fillSearchTree(): void
15
    {
16
        if ($this->document['esearchresult']['count'] !== '1') {
17
            throw new UnparseableApiException();
18
        }
19
20
        $this->searchTree = $this->document['esearchresult'];
21
    }
22
23
    /**
24
     * Extract and format data needed for the Identifiers Relationship
25
     * on the Publication Model.
26
     */
27
    public function extractIdentifiersData(): void
28
    {
29
        foreach ($this->searchTree['idlist'] as $identifier) {
30
            $this->resourceOutput['identifiers'][] = [
31
                'value' => stringify($identifier),
32
                'type' => 'pubmed',
33
            ];
34
        }
35
    }
36
}
37