Css3Image   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 34
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A scrape() 0 15 4
A injectAssetFactory() 0 3 1
1
<?php
2
namespace Aoe\Asdis\Content\Scraper\Html;
3
4
use Aoe\Asdis\Content\Scraper\Html\AbstractHtmlScraper;
5
use Aoe\Asdis\Content\Scraper\ScraperInterface;
6
use Aoe\Asdis\Domain\Model\Asset\Factory;
7
8
/**
9
 * Scrapes assets from all tags by using data-src attributes.
10
 */
11
class Css3Image extends AbstractHtmlScraper implements ScraperInterface
12
{
13
    /**
14
     * @var \Aoe\Asdis\Domain\Model\Asset\Factory
15
     */
16
    private $assetFactory;
17
18
    /**
19
     * @param \Aoe\Asdis\Domain\Model\Asset\Factory $assetFactory
20
     */
21 1
    public function injectAssetFactory(Factory $assetFactory)
22
    {
23 1
        $this->assetFactory = $assetFactory;
24 1
    }
25
26
    /**
27
     * @param string $content
28
     * @return \Aoe\Asdis\Domain\Model\Asset\Collection
29
     */
30 1
    public function scrape($content)
31
    {
32 1
        $paths = [];
33 1
        $masks = [];
34 1
        $matches = [];
35 1
        preg_match_all(
36 1
            '/data-src-[^=]*\s?=\s?([\'"])(.*?)([\'"])/i',
37
            $content,
38
            $matches
39
        );
40 1
        if (is_array($matches) && sizeof($matches) > 1 && is_array($matches[2])) {
41 1
            $paths = $matches[2];
42 1
            $masks = $matches[1];
43
        }
44 1
        return $this->assetFactory->createAssetsFromPaths($paths, $masks);
45
    }
46
}