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

eliashaeussler / typo3-sitemap-locator / 15167920462

21 May 2025 04:48PM CUT coverage: 78.193%. Remained the same
15167920462

Pull #105

github

web-flow
[TASK] Update phpstan/phpstan-symfony to v2.0.6

| datasource | package                 | from  | to    |
| ---------- | ----------------------- | ----- | ----- |
| packagist  | phpstan/phpstan-symfony | 2.0.5 | 2.0.6 |
Pull Request #105: [TASK] Update phpstan/phpstan-symfony to v2.0.6

502 of 642 relevant lines covered (78.19%)

4.53 hits per line

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

100.0
/Classes/Command/Formatter/TextFormatter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "sitemap_locator".
7
 *
8
 * Copyright (C) 2023-2025 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\Typo3SitemapLocator\Command\Formatter;
25

26
use EliasHaeussler\Typo3SitemapLocator\Domain;
27
use EliasHaeussler\Typo3SitemapLocator\Sitemap;
28
use Symfony\Component\Console;
29
use TYPO3\CMS\Core;
30

31
/**
32
 * TextFormatter
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-2.0-or-later
36
 * @internal
37
 */
38
final class TextFormatter implements Formatter
39
{
40
    public function __construct(
14✔
41
        private readonly Console\Output\OutputInterface&Console\Style\StyleInterface $output,
42
        private readonly Sitemap\SitemapLocator $sitemapLocator,
43
    ) {}
14✔
44

45
    public function formatSitemaps(
7✔
46
        Core\Site\Entity\Site $site,
47
        Core\Site\Entity\SiteLanguage $siteLanguage,
48
        array $sitemaps,
49
        bool $validate = false,
50
    ): bool {
51
        if ($sitemaps === []) {
7✔
52
            $this->output->warning(
2✔
53
                sprintf(
2✔
54
                    'No XML sitemaps found for site "%s" (%d) and language "%s" (%d).',
2✔
55
                    $site->getIdentifier(),
2✔
56
                    $site->getRootPageId(),
2✔
57
                    $siteLanguage->getTitle(),
2✔
58
                    $siteLanguage->getLanguageId(),
2✔
59
                ),
2✔
60
            );
2✔
61

62
            return false;
2✔
63
        }
64

65
        $this->output->title(
5✔
66
            sprintf(
5✔
67
                'XML sitemap%s for site "%s" (%d) and language "%s" (%d):',
5✔
68
                count($sitemaps) === 1 ? '' : 's',
5✔
69
                $site->getIdentifier(),
5✔
70
                $site->getRootPageId(),
5✔
71
                $siteLanguage->getTitle(),
5✔
72
                $siteLanguage->getLanguageId(),
5✔
73
            ),
5✔
74
        );
5✔
75

76
        return $this->listSitemapUrls($sitemaps, $validate);
5✔
77
    }
78

79
    public function formatAllSitemaps(
7✔
80
        Core\Site\Entity\Site $site,
81
        array $sitemaps,
82
        bool $validate = false,
83
    ): bool {
84
        $isValid = true;
7✔
85

86
        if ($sitemaps === []) {
7✔
87
            $this->output->warning(
2✔
88
                sprintf(
2✔
89
                    'No XML sitemaps found for site "%s" (%d).',
2✔
90
                    $site->getIdentifier(),
2✔
91
                    $site->getRootPageId(),
2✔
92
                ),
2✔
93
            );
2✔
94

95
            return false;
2✔
96
        }
97

98
        $this->output->title(
5✔
99
            sprintf(
5✔
100
                'XML sitemap%s for site "%s" (%d)',
5✔
101
                count($sitemaps) === 1 ? '' : 's',
5✔
102
                $site->getIdentifier(),
5✔
103
                $site->getRootPageId(),
5✔
104
            ),
5✔
105
        );
5✔
106

107
        foreach ($sitemaps as $languageId => $sitemapsOfLanguage) {
5✔
108
            $siteLanguage = $site->getLanguageById($languageId);
5✔
109

110
            $this->output->section(
5✔
111
                sprintf('Language "%s" (%d)', $siteLanguage->getTitle(), $siteLanguage->getLanguageId()),
5✔
112
            );
5✔
113

114
            if (!$this->listSitemapUrls($sitemapsOfLanguage, $validate)) {
5✔
115
                $isValid = false;
2✔
116
            }
117
        }
118

119
        return $isValid;
5✔
120
    }
121

122
    /**
123
     * @param list<Domain\Model\Sitemap> $sitemaps
124
     */
125
    private function listSitemapUrls(array $sitemaps, bool $validate = false): bool
10✔
126
    {
127
        $isValid = true;
10✔
128
        $sitemapUrls = [];
10✔
129

130
        foreach ($sitemaps as $sitemap) {
10✔
131
            $sitemapUrl = (string)$sitemap->getUri();
10✔
132

133
            if ($validate && !$this->sitemapLocator->isValidSitemap($sitemap)) {
10✔
134
                $isValid = false;
4✔
135
                $sitemapUrl .= ' (<error>invalid</error>)';
4✔
136
            }
137

138
            $sitemapUrls[] = $sitemapUrl;
10✔
139
        }
140

141
        $this->output->listing($sitemapUrls);
10✔
142

143
        return $isValid;
10✔
144
    }
145
}
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