Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 50% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
18 | class Endpoint extends Source |
||
19 | { |
||
20 | use DetectsEndpoints; |
||
21 | use GuzzleAware; |
||
22 | |||
23 | /** |
||
24 | * The endpoint response. |
||
25 | * |
||
26 | * @var ResponseInterface|null |
||
27 | */ |
||
28 | protected ?ResponseInterface $response; |
||
29 | |||
30 | /** |
||
31 | * Retrieve the JSON fragments |
||
32 | * |
||
33 | * @return Traversable<int, string> |
||
34 | * @throws \Cerbero\JsonParser\Exceptions\GuzzleRequiredException |
||
35 | */ |
||
36 | 1 | public function getIterator(): Traversable |
|
37 | { |
||
38 | 1 | $this->requireGuzzle(); |
|
39 | |||
40 | $this->response = $this->getJson($this->source); |
||
41 | |||
42 | return new Psr7Message($this->response, $this->config); |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Determine whether the JSON source can be handled |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | 128 | public function matches(): bool |
|
51 | { |
||
52 | // @phpstan-ignore-next-line |
||
53 | 128 | return (is_string($this->source) || $this->source instanceof UriInterface) && $this->isEndpoint($this->source); |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * Retrieve the calculated size of the JSON source |
||
58 | * |
||
59 | * @return int|null |
||
60 | */ |
||
61 | protected function calculateSize(): ?int |
||
64 | } |
||
65 | } |
||
66 |