Css3Image::injectAssetFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
}