Conditions | 5 |
Paths | 3 |
Total Lines | 34 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 5.0984 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
21 | 2 | public function scrape(string $content): ?Collection |
|
22 | { |
||
23 | 2 | $paths = []; |
|
24 | 2 | $masks = []; |
|
25 | 2 | $matches = []; |
|
26 | 2 | preg_match_all( |
|
27 | 2 | '/srcset=*\s?=\s?([\'"])(.*?)([\'"])/i', |
|
28 | $content, |
||
29 | $matches |
||
30 | ); |
||
31 | |||
32 | 2 | foreach ($matches[2] as $mkey => $path) { |
|
33 | 2 | if (!str_contains($path, ',')) { |
|
34 | $paths[] = $path; |
||
35 | $masks[] = $matches[1][$mkey]; |
||
36 | continue; |
||
37 | } |
||
38 | |||
39 | 2 | $expPaths = explode(',', $path); |
|
40 | |||
41 | 2 | foreach ($expPaths as $singlePath) { |
|
42 | 2 | $cleanSinglePath = trim($singlePath); |
|
43 | |||
44 | 2 | if (str_contains($cleanSinglePath, ' ')) { |
|
45 | 2 | $paths[] = substr($cleanSinglePath, 0, strpos($cleanSinglePath, ' ')); |
|
46 | } else { |
||
47 | 1 | $paths[] = $cleanSinglePath; |
|
48 | } |
||
49 | |||
50 | 2 | $masks[] = ''; |
|
51 | } |
||
52 | } |
||
53 | |||
54 | 2 | return $this->assetFactory->createAssetsFromPaths($paths, $masks); |
|
55 | } |
||
57 |