EutilsEsearch   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 8
c 1
b 0
f 1
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fillSearchTree() 0 7 2
A extractIdentifiersData() 0 6 2
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