AbstractHtmlScraper::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\Extractor\XmlTagAttribute;
5
use Aoe\Asdis\Content\Scraper\ScraperInterface;
6
use Aoe\Asdis\Domain\Model\Asset\Factory;
7
8
/**
9
 * Abstract scraper which provides general functionality to scrape paths from HTML tag attributes.
10
 */
11
abstract class AbstractHtmlScraper
12
{
13
    /**
14
     * @var \Aoe\Asdis\Content\Scraper\Extractor\XmlTagAttribute
15
     */
16
    private $xmlTagAttributeExtractor;
17
18
    /**
19
     * @var \Aoe\Asdis\Domain\Model\Asset\Factory
20
     */
21
    private $assetFactory;
22
23
    /**
24
     * @param \Aoe\Asdis\Content\Scraper\Extractor\XmlTagAttribute $xmlTagAttributeExtractor
25
     */
26 10
    public function injectXmlTagAttributeExtractor(XmlTagAttribute $xmlTagAttributeExtractor)
27
    {
28 10
        $this->xmlTagAttributeExtractor = $xmlTagAttributeExtractor;
29 10
    }
30
31
    /**
32
     * @param \Aoe\Asdis\Domain\Model\Asset\Factory $assetFactory
33
     */
34 10
    public function injectAssetFactory(Factory $assetFactory)
35
    {
36 10
        $this->assetFactory = $assetFactory;
37 10
    }
38
39
    /**
40
     * @param string $tagName
41
     * @param string $attributeName
42
     * @param string $content
43
     * @param array $requiredOtherAttributes
44
     * @return \Aoe\Asdis\Domain\Model\Asset\Collection
45
     */
46 10
    protected function getAssets($tagName, $attributeName, $content, array $requiredOtherAttributes = [])
47
    {
48 10
        $attributes = $this->xmlTagAttributeExtractor->getAttributeFromTag(
49 10
            $tagName, $attributeName, $content, $requiredOtherAttributes
50
        );
51 10
        return $this->assetFactory->createAssetsFromPaths(
52 10
            $attributes['paths'],
53 10
            $attributes['masks']
54
        );
55
    }
56
}