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

ChainFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 56.25%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 45
ccs 9
cts 16
cp 0.5625
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildChain() 0 10 2
A initialize() 0 5 1
A buildScraper() 0 4 1
A getScraperDeclarations() 0 7 2
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
}