| Total Complexity | 5 |
| Total Lines | 47 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | abstract class Query |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Psr7 compatible client. |
||
| 18 | * |
||
| 19 | * @var \GuzzleHttp\Client |
||
| 20 | */ |
||
| 21 | protected $httpClient; |
||
| 22 | |||
| 23 | public function __construct($httpClient) |
||
| 24 | { |
||
| 25 | $this->httpClient = $httpClient; |
||
| 26 | } |
||
| 27 | |||
| 28 | protected function fetchContentAsArray(string $url): ?array |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param string $url |
||
| 38 | * @param \Jakim\Base\Mapper $mapper |
||
| 39 | * @param bool $relations |
||
| 40 | * @return mixed |
||
| 41 | * @throws \Jakim\Exception\EmptyContentException |
||
| 42 | * @throws \Jakim\Exception\LoginAndSignupPageException |
||
| 43 | * @throws \Jakim\Exception\RestrictedProfileException |
||
| 44 | */ |
||
| 45 | protected function createResult(string $url, Mapper $mapper, bool $relations) |
||
| 46 | { |
||
| 47 | $content = $this->fetchContentAsArray($url); |
||
| 48 | |||
| 49 | $this->throwEmptyContentExceptionIfEmpty($content); |
||
| 50 | |||
| 51 | $config = $mapper->config(); |
||
| 52 | $data = $mapper->getData($content, $config); |
||
| 53 | |||
| 54 | return $mapper->createModel($data, $config, $relations); |
||
| 55 | } |
||
| 56 | |||
| 57 | protected function throwEmptyContentExceptionIfEmpty($content) |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } |