| Total Complexity | 6 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class EutilsEsearch implements Extractor, ProvidesIdentifiersData |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var |
||
| 11 | */ |
||
| 12 | protected $document; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var |
||
| 16 | */ |
||
| 17 | protected $searchTree; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var |
||
| 21 | */ |
||
| 22 | protected $output; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * EutilsEsearch constructor. |
||
| 26 | * |
||
| 27 | * @param $document |
||
| 28 | */ |
||
| 29 | public function __construct($document) |
||
| 30 | { |
||
| 31 | $this->document = $document; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @throws UnparseableApiException |
||
| 36 | * @return array |
||
| 37 | */ |
||
| 38 | public function extract(): array |
||
| 39 | { |
||
| 40 | $this->getDataFromDocument(); |
||
| 41 | $this->extractIdentifiersData(); |
||
| 42 | |||
| 43 | return $this->output; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Extract search tree from document. |
||
| 48 | * |
||
| 49 | * @throws UnparseableApiException |
||
| 50 | */ |
||
| 51 | protected function getDataFromDocument() |
||
| 52 | { |
||
| 53 | if ($this->document['esearchresult']['count'] !== '1') { |
||
| 54 | throw new UnparseableApiException(); |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->searchTree = $this->document['esearchresult']; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Extract and format data needed for the Identifiers Relationship |
||
| 62 | * on the Publication Model. |
||
| 63 | */ |
||
| 64 | public function extractIdentifiersData() |
||
| 70 | ]; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 |