| Total Complexity | 7 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class IdConverter implements Extractor, ProvidesIdentifiersData |
||
| 8 | { |
||
| 9 | protected $document; |
||
| 10 | |||
| 11 | protected $searchTree; |
||
| 12 | |||
| 13 | protected $typeMap = [ |
||
| 14 | 'pmcid' => 'pmc', |
||
| 15 | 'pmid' => 'pubmed', |
||
| 16 | 'doi' => 'doi' |
||
| 17 | ]; |
||
| 18 | |||
| 19 | protected $output; |
||
| 20 | |||
| 21 | public function __construct($document) |
||
| 22 | { |
||
| 23 | $this->document = $document; |
||
| 24 | } |
||
| 25 | |||
| 26 | public function extract(): array |
||
| 27 | { |
||
| 28 | $this->getDataFromDocument(); |
||
| 29 | $this->extractIdentifiersData(); |
||
| 30 | |||
| 31 | return $this->output; |
||
| 32 | } |
||
| 33 | |||
| 34 | protected function getDataFromDocument() |
||
| 35 | { |
||
| 36 | if ('ok' !== $this->document['status']) { |
||
| 37 | throw new UnparseableApiException(); |
||
| 38 | } |
||
| 39 | |||
| 40 | $this->searchTree = $this->document['records'][0]; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function extractIdentifiersData() |
||
| 50 | ]; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | } |
||
| 55 |