| Conditions | 5 |
| Paths | 5 |
| Total Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | public function getUrlByTitle(string $originalTitle): string |
||
| 12 | { |
||
| 13 | $endpoint = strtr(self::ENDPOINT, [ |
||
| 14 | '{title}' => urlencode($originalTitle) |
||
| 15 | ]); |
||
| 16 | |||
| 17 | $html = $this->getHtml($endpoint); |
||
| 18 | |||
| 19 | if (!$html) { |
||
| 20 | throw new \ErrorException('Html cant be loaded'); |
||
| 21 | } |
||
| 22 | |||
| 23 | $crawler = new Crawler($html); |
||
| 24 | $searchTitle = trim($crawler->filter('.search-results-title')->first()->text()); |
||
| 25 | |||
| 26 | if (!$searchTitle) { |
||
| 27 | throw new \ErrorException('Cant find search title'); |
||
| 28 | } |
||
| 29 | |||
| 30 | $firstWord = current(explode(' ', $searchTitle)); |
||
| 31 | if (mb_strtolower($firstWord) !== 'найдено') { |
||
| 32 | throw new \ErrorException('This movie not found on megogo'); |
||
| 33 | } |
||
| 34 | |||
| 35 | $url = $crawler->filter('a.invisible-overlay')->first()->attr('href'); |
||
| 36 | |||
| 37 | if (!$url) { |
||
|
|
|||
| 38 | throw new \ErrorException('Url of movie not found'); |
||
| 39 | } |
||
| 40 | |||
| 41 | return 'https://megogo.net' . $url; |
||
| 42 | } |
||
| 43 | |||
| 60 | } |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: