| Total Complexity | 8 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 88.89% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | final class ScrapingReviewerLinkExtractor |
||
| 12 | { |
||
| 13 | 10 | public function __construct(private Crawler $crawler) |
|
| 14 | { |
||
| 15 | } |
||
| 16 | |||
| 17 | 11 | public static function fromUrlResponse(UrlResponse $response): self |
|
| 18 | { |
||
| 19 | 11 | if (empty($response->body())) { |
|
| 20 | 1 | throw new RuntimeException('Content is empty'); |
|
| 21 | } |
||
| 22 | 10 | $crawler = new Crawler($response->body(), $response->url()); |
|
| 23 | 10 | return new self($crawler); |
|
| 24 | } |
||
| 25 | |||
| 26 | 10 | public function search(string $search): string |
|
| 27 | { |
||
| 28 | 10 | $link = $this->selectLink($search); |
|
| 29 | 10 | $downloadUrl = $link->getUri(); |
|
| 30 | |||
| 31 | 10 | if (empty($downloadUrl)) { |
|
| 32 | throw new RuntimeException('The link was found but it does not contains the url to download'); |
||
| 33 | } |
||
| 34 | |||
| 35 | 10 | return $downloadUrl; |
|
| 36 | } |
||
| 37 | |||
| 38 | 10 | public function selectLink(string $search): Link |
|
| 50 | } |
||
| 51 | } |
||
| 52 |