ContentPostProcOutputHook::__construct()   A
last analyzed

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\Varnish\TYPO3\Hooks;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2019 AOE GmbH <[email protected]>
8
 *
9
 *  All rights reserved
10
 *
11
 *  This script is part of the TYPO3 project. The TYPO3 project is
12
 *  free software; you can redistribute it and/or modify
13
 *  it under the terms of the GNU General Public License as published by
14
 *  the Free Software Foundation; either version 3 of the License, or
15
 *  (at your option) any later version.
16
 *
17
 *  The GNU General Public License can be found at
18
 *  http://www.gnu.org/copyleft/gpl.html.
19
 *
20
 *  This script is distributed in the hope that it will be useful,
21
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 *  GNU General Public License for more details.
24
 *
25
 *  This copyright notice MUST APPEAR in all copies of the script!
26
 ***************************************************************/
27
28
use Aoe\Varnish\Domain\Model\Tag\PageTag;
29
use Aoe\Varnish\Domain\Model\Tag\PageIdTag;
30
use Aoe\Varnish\System\Header;
31
use Aoe\Varnish\TYPO3\Configuration\ExtensionConfiguration;
32
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
33
34
class ContentPostProcOutputHook extends AbstractHook
35
{
36
    const TYPO3_PAGE_TAG = 'typo3_page';
37
38
    /**
39
     * @var Header
40
     */
41
    private $header;
42
43 3
    public function __construct()
44
    {
45 3
        parent::__construct();
46 3
        $this->header = new Header();
47 3
    }
48
49
    /**
50
     * @param array $parameters
51
     * @param TypoScriptFrontendController $parent
52
     */
53 3
    public function sendHeader(array $parameters, TypoScriptFrontendController $parent)
0 ignored issues
show
Unused Code introduced by
The parameter $parameters is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
    {
55 3
        $this->sendPageTagHeader($parent);
56 3
        $this->sendDebugHeader();
57 3
        if ((int)$parent->page['varnish_cache'] === 1) {
58 2
            $this->header->sendEnabledHeader();
59
        }
60 3
    }
61
62
    /**
63
     * @param TypoScriptFrontendController $parent
64
     * @return void
65
     */
66 3
    private function sendPageTagHeader(TypoScriptFrontendController $parent)
67
    {
68 3
        $pageIdTag = new PageIdTag($parent->id);
69 3
        $pageTag = new PageTag(self::TYPO3_PAGE_TAG);
0 ignored issues
show
Unused Code introduced by
The call to PageTag::__construct() has too many arguments starting with self::TYPO3_PAGE_TAG.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
70
71 3
        $this->header->sendHeaderForTag($pageIdTag);
72 3
        $this->header->sendHeaderForTag($pageTag);
73 3
    }
74
75
    /**
76
     * @return void
77
     */
78 3
    private function sendDebugHeader()
79
    {
80
        /** @var ExtensionConfiguration $configuration */
81 3
        $configuration = $this->objectManager->get(ExtensionConfiguration::class);
82 3
        if ($configuration->isDebug()) {
83 2
            $this->header->sendDebugHeader();
84
        }
85 3
    }
86
}
87