Lines
77.77%
7 / 9
Methods
50.00%
1 / 2
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| extractDistrictUrls | 75.00% | 6 / 8 | 0.00% | 0 / 1 | 4.25 | ||
| 11 | readonly class CityParser | |
| 12 | { | |
| 13 | public function __construct( | |
| 14 | private HtmlFinder $htmlFinder, | |
| 15 | ) { | |
| 16 | } | |
| 17 | ||
| 18 | /** | |
| 19 | * @return iterable<string> | |
| 20 | */ | |
| 21 | public function extractDistrictUrls(string $html): iterable | |
| 22 | { | |
| 23 | // phpcs:ignore Generic.Files.LineLength.TooLong | |
| 24 | $xpath = "//a[contains(@class, 'nav-link') and .='Dzielnice']/following::ul/li/a[@class='nav-link' and starts-with(., 'Dzielnica ')]"; | |
| 25 | try { | |
| 26 | $nodes = $this->htmlFinder->findNodes($html, $xpath); | |
| 27 | } catch (InvalidHtmlException) { | |
| 28 | throw new ParsingException(); | |
| 29 | } | |
| 30 | if (count($nodes) < 1) { | |
| 31 | throw new ParsingException(); | |
| 32 | } | |
| 33 | foreach ($nodes as $node) { | |
| 34 | yield $this->htmlFinder->getAttribute($node, "href"); | |
| 35 | } | |
| 36 | } | |
| 37 | } |