These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Spatie\MixedContentScanner; |
||
4 | |||
5 | use Spatie\Crawler\Url; |
||
6 | use Illuminate\Support\Collection; |
||
7 | use Symfony\Component\DomCrawler\Link; |
||
8 | use Symfony\Component\DomCrawler\Crawler as DomCrawler; |
||
9 | |||
10 | class MixedContentExtractor |
||
11 | { |
||
12 | public static function extract(string $html, string $currentUri): array |
||
13 | { |
||
14 | return static::getSearchNodes() |
||
15 | ->map(function (array $nodeProperties) use ($html, $currentUri) { |
||
16 | [$elementName, $attribute] = $nodeProperties; |
||
0 ignored issues
–
show
|
|||
17 | |||
18 | return (new DomCrawler($html, $currentUri)) |
||
19 | ->filterXPath("//{$elementName}[@{$attribute}]") |
||
20 | ->each(function (DomCrawler $node) use ($elementName, $attribute) { |
||
21 | $url = Url::create($node->attr($attribute)); |
||
22 | |||
23 | return [$elementName, $url]; |
||
24 | }); |
||
25 | }) |
||
26 | ->flatten(1) |
||
27 | ->filter() |
||
28 | ->filter(function (array $nodeProperties) { |
||
29 | [$elementName, $url] = $nodeProperties; |
||
0 ignored issues
–
show
The variable
$elementName does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.
Loading history...
|
|||
30 | |||
31 | return $url->scheme === 'http'; |
||
32 | }) |
||
33 | ->map(function (array $nodeProperties) use ($currentUri) { |
||
34 | [$elementName, $mixedContentUrl] = $nodeProperties; |
||
0 ignored issues
–
show
The variable
$elementName does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.
Loading history...
The variable
$mixedContentUrl does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.
Loading history...
|
|||
35 | |||
36 | return new MixedContent($elementName, $mixedContentUrl, Url::create($currentUri)); |
||
37 | }) |
||
38 | ->toArray(); |
||
39 | } |
||
40 | |||
41 | protected static function getSearchNodes(): Collection |
||
42 | { |
||
43 | return collect([ |
||
44 | 'audio' => ['src'], |
||
45 | 'embed' => ['src'], |
||
46 | 'form' => ['action'], |
||
47 | 'link' => ['href'], |
||
48 | 'iframe' => ['src'], |
||
49 | 'img' => ['src', 'srcset'], |
||
50 | 'object' => ['data'], |
||
51 | 'param' => ['value'], |
||
52 | 'script' => ['src'], |
||
53 | 'source' => ['src', 'srcset'], |
||
54 | 'video' => ['src'], |
||
55 | ]) |
||
56 | ->flatMap(function (array $attributes, string $element) { |
||
57 | return collect($attributes) |
||
58 | ->map(function (string $attribute) use ($element) { |
||
59 | return [$element, $attribute]; |
||
60 | }); |
||
61 | }); |
||
62 | } |
||
63 | } |
||
64 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.