AbstractHtmlScraper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A injectXmlTagAttributeExtractor() 0 3 1
A injectAssetFactory() 0 3 1
A getAssets() 0 8 1
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
}