Completed
Push — develop ( 3f30aa...2ed48f )
by Tino
07:19
created

Title::renderHomepageTitle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 0
dl 0
loc 16
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (c) by the ACP3 Developers.
5
 * See the LICENSE file at the top-level module directory for licensing details.
6
 */
7
8
namespace ACP3\Modules\ACP3\System\Core\Breadcrumb;
9
10
use ACP3\Core\Breadcrumb\Steps;
11
use ACP3\Core\Http\RequestInterface;
12
use ACP3\Core\Settings\SettingsInterface;
13
use ACP3\Modules\ACP3\System\Installer\Schema;
14
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15
16
class Title extends \ACP3\Core\Breadcrumb\Title
17
{
18
    /**
19
     * @var SettingsInterface
20
     */
21
    private $settings;
22
    /**
23
     * @var RequestInterface
24
     */
25
    private $request;
26
    /**
27
     * @var array
28
     */
29
    private $systemSettings = [];
30
31
    /**
32
     * Title constructor.
33
     *
34
     * @param RequestInterface         $request
35
     * @param Steps                    $steps
36
     * @param EventDispatcherInterface $eventDispatcher
37
     * @param SettingsInterface        $settings
38
     */
39
    public function __construct(
40
        RequestInterface $request,
41
        Steps $steps,
42
        EventDispatcherInterface $eventDispatcher,
43
        SettingsInterface $settings
44
    ) {
45
        parent::__construct($steps, $eventDispatcher);
46
47
        $this->settings = $settings;
48
        $this->request = $request;
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    private function getSettings()
55
    {
56
        if (empty($this->systemSettings)) {
57
            $this->systemSettings = $this->settings->getSettings(Schema::MODULE_NAME);
58
        }
59
60
        return $this->systemSettings;
61
    }
62
63
    public function getSiteAndPageTitle()
64
    {
65
        if ($this->request->isHomepage()) {
66
            return $this->renderHomepageTitle();
67
        }
68
69
        $settings = $this->getSettings();
70
        if ($this->allowSystemSubtitle() && $settings['site_subtitle_mode'] == 2) {
71
            $this->setSiteSubtitle('');
72
        }
73
74
        return parent::getSiteAndPageTitle();
75
    }
76
77
    private function renderHomepageTitle(): string
78
    {
79
        if ($this->allowSystemSubtitle()) {
80
            $settings = $this->getSettings();
81
82
            if ($settings['site_subtitle_homepage_mode'] == 1) {
83
                $this->setMetaTitle($this->getSiteSubtitle());
0 ignored issues
show
Bug introduced by Tino Goratsch
It seems like $this->getSiteSubtitle() can also be of type null; however, parameter $metaTitle of ACP3\Core\Breadcrumb\Title::setMetaTitle() does only seem to accept string, 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

83
                $this->setMetaTitle(/** @scrutinizer ignore-type */ $this->getSiteSubtitle());
Loading history...
84
                $this->setSiteSubtitle('');
85
            }
86
        }
87
88
        return $this->renderSiteTitle()
89
            . $this->renderSiteSubTitle()
90
            . $this->renderPageTitlePrefix()
91
            . $this->renderPageTitle()
92
            . $this->renderPageTitleSuffix();
93
    }
94
95
    private function allowSystemSubtitle(): bool
96
    {
97
        return $this->getSettings()['site_subtitle_mode'] != 3;
98
    }
99
100
    protected function renderSiteSubTitle(): string
101
    {
102
        if ($this->allowSystemSubtitle()) {
103
            if ($this->request->isHomepage() && !empty($this->getSiteSubtitle())) {
104
                return $this->getSiteSubtitle() . $this->getPageTitleSeparator();
105
            }
106
107
            return parent::renderSiteSubTitle();
108
        }
109
110
        return '';
111
    }
112
113
    protected function renderSiteTitle(): string
114
    {
115
        if ($this->request->isHomepage() && !empty($this->getSiteTitle())) {
116
            return $this->getSiteTitle() . $this->getPageTitleSeparator();
117
        }
118
119
        return parent::renderSiteTitle();
120
    }
121
}
122