Passed
Push — master ( 6ba3d6...287c0c )
by Xavier
05:28
created

PubmedWebsite::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace PubPeerFoundation\PublicationDataExtractor\Resources\Extractors;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
7
class PubmedWebsite extends Extractor implements ProvidesIdentifiersData, ProvidesAffiliationsData
8
{
9
    /**
10
     * @var Crawler
11
     */
12
    protected $crawler;
13
14
    /**
15
     * Create search tree.
16
     */
17
    protected function getDataFromDocument()
18
    {
19
        $this->crawler = new Crawler();
20
        $this->crawler->addHtmlContent($this->document);
21
    }
22
23
    /**
24
     * Extract and format data needed for the Identifiers Relationship
25
     * on the Publication Model.
26
     */
27
    public function extractIdentifiersData()
28
    {
29
        $pubmed = stringify($this->crawler->evaluate('string(//input[@id="absid"]/@value)'));
30
31
        if (! empty($pubmed)) {
32
            $this->output['identifiers'][] = [
33
                'value' => $pubmed,
34
                'type' => 'pubmed',
35
            ];
36
        }
37
    }
38
39
    /**
40
     * Extract and format data needed for the Affiliations Relationship
41
     * on the Publication Model.
42
     */
43
    public function extractAffiliationsData()
44
    {
45
        $affiliations = $this->crawler->evaluate('//div[@class="afflist"]/dl/dd');
46
47
        foreach ($affiliations as $affiliation) {
48
            $this->output['affiliations'][] = [
49
                'name' => (string) $affiliation->textContent,
50
            ];
51
        }
52
    }
53
}
54