Completed
Pull Request — master (#12)
by
unknown
01:57
created

ChainFactory::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace Aoe\Asdis\Content\Scraper;
3
4
use Aoe\Asdis\Content\Scraper\Chain;
5
use Aoe\Asdis\Content\Scraper\ScraperInterface;
6
use Aoe\Asdis\System\Factory\AbstractDeclarationBasedFactory;
7
8
/**
9
 * Scraper chain factory.
10
 */
11
class ChainFactory extends AbstractDeclarationBasedFactory
12
{
13
    /**
14
     * @return \Aoe\Asdis\Content\Scraper\Chain
15
     */
16 1
    public function buildChain()
17
    {
18 1
        $this->initialize();
19
        /** @var \Aoe\Asdis\Content\Scraper\Chain $chain */
20 1
        $chain = $this->objectManager->get(Chain::class);
21 1
        foreach($this->configurationProvider->getScraperKeys() as $scraperKey) {
22
            $chain->append($this->buildScraper($scraperKey));
23
        }
24 1
        return $chain;
25
    }
26
27
    /**
28
     * @return void
29
     */
30 1
    private function initialize()
31
    {
32 1
        $this->setDeclarations($this->getScraperDeclarations());
33 1
        $this->setClassImplements(['Aoe\Asdis\Content\Scraper\ScraperInterface']);
34 1
    }
35
36
    /**
37
     * @param string $scraperKey
38
     * @return \Aoe\Asdis\Content\Scraper\ScraperInterface
39
     */
40
    private function buildScraper($scraperKey)
41
    {
42
        return $this->buildObjectFromKey($scraperKey);
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    protected function getScraperDeclarations()
49
    {
50
        if (false === isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['asdis']['scrapers'])) {
51
            return array();
52
        }
53
        return $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['asdis']['scrapers'];
54
    }
55
}