• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-warming / 8467139501

28 Mar 2024 12:19PM UTC coverage: 91.286%. Remained the same
8467139501

push

github

web-flow
[TASK] Update eslint-plugin-sonarjs to ^0.25.0

| datasource | package               | from   | to     |
| ---------- | --------------------- | ------ | ------ |
| npm        | eslint-plugin-sonarjs | 0.24.0 | 0.25.0 |

1079 of 1182 relevant lines covered (91.29%)

8.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/Classes/Controller/FetchSitesController.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "warming".
7
 *
8
 * Copyright (C) 2021-2024 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3Warming\Controller;
25

26
use EliasHaeussler\Typo3SitemapLocator;
27
use EliasHaeussler\Typo3Warming\Configuration;
28
use EliasHaeussler\Typo3Warming\Crawler;
29
use EliasHaeussler\Typo3Warming\Http;
30
use EliasHaeussler\Typo3Warming\Utility;
31
use EliasHaeussler\Typo3Warming\ValueObject;
32
use Psr\Http\Message;
33
use TYPO3\CMS\Backend;
34
use TYPO3\CMS\Core;
35

36
/**
37
 * FetchSitesController
38
 *
39
 * @author Elias Häußler <elias@haeussler.dev>
40
 * @license GPL-2.0-or-later
41
 */
42
final class FetchSitesController
43
{
44
    public function __construct(
6✔
45
        private readonly Configuration\Configuration $configuration,
46
        private readonly Crawler\Strategy\CrawlingStrategyFactory $crawlingStrategyFactory,
47
        private readonly Core\Imaging\IconFactory $iconFactory,
48
        private readonly Http\Message\ResponseFactory $responseFactory,
49
        private readonly Core\Site\SiteFinder $siteFinder,
50
        private readonly Typo3SitemapLocator\Sitemap\SitemapLocator $sitemapLocator,
51
    ) {}
6✔
52

53
    /**
54
     * @throws Typo3SitemapLocator\Exception\BaseUrlIsNotSupported
55
     * @throws Typo3SitemapLocator\Exception\SitemapIsMissing
56
     */
57
    public function __invoke(): Message\ResponseInterface
6✔
58
    {
59
        $siteGroups = [];
6✔
60

61
        foreach (array_filter($this->siteFinder->getAllSites(), Utility\AccessUtility::canWarmupCacheOfSite(...)) as $site) {
6✔
62
            $row = Backend\Utility\BackendUtility::getRecord('pages', $site->getRootPageId(), '*', ' AND hidden = 0');
6✔
63

64
            if (\is_array($row)) {
6✔
65
                $siteGroups[] = $this->createSiteGroup($site, $row);
6✔
66
            }
67
        }
68

69
        return $this->responseFactory->htmlTemplate('Modal/SitesModal', [
6✔
70
            'siteGroups' => array_filter($siteGroups),
6✔
71
            'userAgent' => $this->configuration->getUserAgent(),
6✔
72
            'configuration' => [
6✔
73
                'limit' => $this->configuration->getLimit(),
6✔
74
                'strategy' => $this->configuration->getStrategy(),
6✔
75
            ],
6✔
76
            'availableStrategies' => array_keys($this->crawlingStrategyFactory->getAll()),
6✔
77
            'isAdmin' => Utility\BackendUtility::getBackendUser()->isAdmin(),
6✔
78
        ]);
6✔
79
    }
80

81
    /**
82
     * @param array<string, mixed> $page
83
     * @throws Typo3SitemapLocator\Exception\BaseUrlIsNotSupported
84
     * @throws Typo3SitemapLocator\Exception\SitemapIsMissing
85
     */
86
    private function createSiteGroup(Core\Site\Entity\Site $site, array $page): ?ValueObject\Modal\SiteGroup
6✔
87
    {
88
        $items = [];
6✔
89

90
        // Check all available languages for possible sitemaps
91
        foreach ($this->sitemapLocator->locateAllBySite($site) as $i => $sitemaps) {
6✔
92
            foreach ($sitemaps as $sitemap) {
6✔
93
                $siteLanguage = $sitemap->getSiteLanguage();
6✔
94
                $url = null;
6✔
95

96
                // Check if sitemap exists
97
                if ($this->sitemapLocator->isValidSitemap($sitemap)) {
6✔
98
                    $url = (string)$sitemap->getUri();
6✔
99
                }
100

101
                $items[] = new ValueObject\Modal\SiteGroupItem(
6✔
102
                    $siteLanguage,
6✔
103
                    $siteLanguage === $site->getDefaultLanguage(),
6✔
104
                    $url,
6✔
105
                );
6✔
106
            }
107
        }
108

109
        // Early return if no languages are available
110
        if ($items === []) {
6✔
111
            return null;
×
112
        }
113

114
        return new ValueObject\Modal\SiteGroup(
6✔
115
            $site,
6✔
116
            $this->resolvePageTitle($site, $page),
6✔
117
            $this->iconFactory->getIconForRecord('pages', $page)->getIdentifier(),
6✔
118
            $items,
6✔
119
        );
6✔
120
    }
121

122
    /**
123
     * @param array<string, mixed> $page
124
     */
125
    private function resolvePageTitle(Core\Site\Entity\Site $site, array $page): string
6✔
126
    {
127
        $websiteTitle = $site->getConfiguration()['websiteTitle'] ?? null;
6✔
128

129
        if (\is_string($websiteTitle) && trim($websiteTitle) !== '') {
6✔
130
            return $websiteTitle;
×
131
        }
132

133
        return Backend\Utility\BackendUtility::getRecordTitle('pages', $page);
6✔
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc