Passed
Pull Request — master (#16)
by
unknown
13:19 queued 10:34
created

Page   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 14.29%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 94
ccs 6
cts 42
cp 0.1429
rs 10
wmc 14

11 Methods

Rating   Name   Duplication   Size   Complexity  
A injectDistributionAlgorithmFactory() 0 3 1
A setPageObject() 0 3 1
A replaceAssets() 0 16 3
A injectReplacementProcessor() 0 3 1
A getAssets() 0 3 1
A setAssets() 0 3 1
A injectConfigurationProvider() 0 3 1
A injectScraperChainFactory() 0 3 1
A getPageObject() 0 3 1
A injectServerRepository() 0 3 1
A scrapeAssets() 0 6 2
1
<?php
2
3
namespace Aoe\Asdis\Domain\Model;
4
5
use Aoe\Asdis\Content\Replacement\Processor;
6
use Aoe\Asdis\Content\Scraper\ChainFactory;
7
use Aoe\Asdis\Domain\Model\Asset\Collection;
8
use Aoe\Asdis\Domain\Model\DistributionAlgorithm\Factory;
9
use Aoe\Asdis\Domain\Repository\ServerRepository;
10
use Aoe\Asdis\System\Configuration\Provider;
11
use Exception;
12
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
13
14
/**
15
 * Represents a page in the TYPO3 page tree.
16
 */
17
class Page
18
{
19
    private ?Collection $assets = null;
20
21
    private ?TypoScriptFrontendController $pageObject = null;
22
23
    private ?ChainFactory $scraperChainFactory = null;
24
25
    private ?Factory $distributionAlgorithmFactory = null;
26
27
    private ?ServerRepository $serverRepository = null;
28
29
    private ?Provider $configurationProvider = null;
30
31
    private ?Processor $replacementProcessor = null;
32
33
    public function injectScraperChainFactory(ChainFactory $scraperChainFactory): void
34
    {
35
        $this->scraperChainFactory = $scraperChainFactory;
36
    }
37
38
    public function injectDistributionAlgorithmFactory(Factory $distributionAlgorithmFactory): void
39
    {
40
        $this->distributionAlgorithmFactory = $distributionAlgorithmFactory;
41
    }
42
43
    public function injectServerRepository(ServerRepository $serverRepository): void
44
    {
45
        $this->serverRepository = $serverRepository;
46
    }
47
48 1
    public function injectConfigurationProvider(Provider $configurationProvider): void
49
    {
50 1
        $this->configurationProvider = $configurationProvider;
51 1
    }
52
53
    public function injectReplacementProcessor(Processor $replacementProcessor): void
54
    {
55
        $this->replacementProcessor = $replacementProcessor;
56
    }
57
58
    /**
59
     * Scrapes the assets of the page. There is no replacement taking place. You have to call "replaceAssets" to replace
60
     * the paths after calling "scrapeAssets".
61
     */
62 1
    public function scrapeAssets(): void
63
    {
64 1
        if (!$this->configurationProvider->isReplacementEnabled()) {
0 ignored issues
show
Bug introduced by
The method isReplacementEnabled() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        if (!$this->configurationProvider->/** @scrutinizer ignore-call */ isReplacementEnabled()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65 1
            return;
66
        }
67
        $this->setAssets($this->scraperChainFactory->buildChain()->scrape($this->pageObject->content));
0 ignored issues
show
Bug introduced by
The method buildChain() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

67
        $this->setAssets($this->scraperChainFactory->/** @scrutinizer ignore-call */ buildChain()->scrape($this->pageObject->content));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
68
    }
69
70
    /**
71
     * Replaces the assets of the page.
72
     * To force any replacement, you have to call "scrapeAssets" before.
73
     */
74
    public function replaceAssets(): void
75
    {
76
        if (!$this->configurationProvider->isReplacementEnabled()) {
77
            return;
78
        }
79
        $distributionAlgorithmKey = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $distributionAlgorithmKey is dead and can be removed.
Loading history...
80
        try {
81
            $distributionAlgorithmKey = $this->configurationProvider->getDistributionAlgorithmKey();
82
        } catch (Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
83
        }
84
        $distributionAlgorithm = $this->distributionAlgorithmFactory->buildDistributionAlgorithmFromKey($distributionAlgorithmKey);
0 ignored issues
show
Bug introduced by
The method buildDistributionAlgorithmFromKey() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
        /** @scrutinizer ignore-call */ 
85
        $distributionAlgorithm = $this->distributionAlgorithmFactory->buildDistributionAlgorithmFromKey($distributionAlgorithmKey);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
85
        $distributionAlgorithm->distribute($this->assets, $this->serverRepository->findAllByPage($this));
0 ignored issues
show
Bug introduced by
The method findAllByPage() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        $distributionAlgorithm->distribute($this->assets, $this->serverRepository->/** @scrutinizer ignore-call */ findAllByPage($this));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
It seems like $this->assets can also be of type null; however, parameter $assets of Aoe\Asdis\Domain\Model\D...Interface::distribute() does only seem to accept Aoe\Asdis\Domain\Model\Asset\Collection, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

85
        $distributionAlgorithm->distribute(/** @scrutinizer ignore-type */ $this->assets, $this->serverRepository->findAllByPage($this));
Loading history...
86
87
        $this->pageObject->content = $this->replacementProcessor->replace(
0 ignored issues
show
Bug introduced by
The method replace() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
        /** @scrutinizer ignore-call */ 
88
        $this->pageObject->content = $this->replacementProcessor->replace(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
            $this->assets->getReplacementMap(),
0 ignored issues
show
Bug introduced by
The method getReplacementMap() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
            $this->assets->/** @scrutinizer ignore-call */ 
89
                           getReplacementMap(),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
            $this->pageObject->content
90
        );
91
    }
92
93
    public function setAssets(Collection $assets): void
94
    {
95
        $this->assets = $assets;
96
    }
97
98
    public function setPageObject(TypoScriptFrontendController $pageObject): void
99
    {
100
        $this->pageObject = $pageObject;
101
    }
102
103
    public function getPageObject(): ?TypoScriptFrontendController
104
    {
105
        return $this->pageObject;
106
    }
107
108
    public function getAssets(): ?Collection
109
    {
110
        return $this->assets;
111
    }
112
}
113