Conditions | 4 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
12 | public static function extract(string $html, string $currentUri): array |
||
13 | { |
||
14 | return static::getSearchNodes() |
||
15 | ->mapSpread(function ($tagName, $attribute) use ($html, $currentUri) { |
||
16 | return (new DomCrawler($html, $currentUri)) |
||
17 | ->filterXPath("//{$tagName}[@{$attribute}]") |
||
18 | ->reduce(function (DomCrawler $node) { |
||
19 | $relAttr = $node->getNode(0)->attributes->getNamedItem('rel'); |
||
20 | |||
21 | if ($relAttr !== null && strtolower($relAttr->nodeValue) === 'shortlink') { |
||
22 | return false; |
||
23 | } |
||
24 | |||
25 | return true; |
||
26 | }) |
||
27 | ->each(function (DomCrawler $node) use ($tagName, $attribute) { |
||
28 | $url = Url::create($node->attr($attribute)); |
||
29 | |||
30 | return $url->scheme === 'http' ? [$tagName, $url] : null; |
||
31 | }); |
||
32 | }) |
||
33 | ->flatten(1) |
||
34 | ->filter() |
||
35 | ->mapSpread(function ($tagName, $mixedContentUrl) use ($currentUri) { |
||
36 | return new MixedContent($tagName, $mixedContentUrl, Url::create($currentUri)); |
||
37 | }) |
||
38 | ->toArray(); |
||
39 | } |
||
40 | |||
60 |