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

eliashaeussler / cache-warmup / 10495565513

21 Aug 2024 06:38PM UTC coverage: 94.463%. Remained the same
10495565513

Pull #389

github

web-flow
[TASK] Update paambaati/codeclimate-action action to v9

| datasource  | package                      | from   | to     |
| ----------- | ---------------------------- | ------ | ------ |
| github-tags | paambaati/codeclimate-action | v8.0.0 | v9.0.0 |
Pull Request #389: [TASK] Update paambaati/codeclimate-action action to v9

1433 of 1517 relevant lines covered (94.46%)

9.11 hits per line

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

95.0
/src/Formatter/TextFormatter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/cache-warmup".
7
 *
8
 * Copyright (C) 2020-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 3 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\CacheWarmup\Formatter;
25

26
use EliasHaeussler\CacheWarmup\Helper;
27
use EliasHaeussler\CacheWarmup\Result;
28
use EliasHaeussler\CacheWarmup\Time;
29
use Symfony\Component\Console;
30

31
use function call_user_func;
32
use function method_exists;
33
use function sprintf;
34

35
/**
36
 * TextFormatter.
37
 *
38
 * @author Elias Häußler <elias@haeussler.dev>
39
 * @license GPL-3.0-or-later
40
 */
41
final class TextFormatter implements Formatter
42
{
43
    public function __construct(
20✔
44
        private readonly Console\Style\SymfonyStyle $io,
45
    ) {
46
        Helper\ConsoleHelper::registerAdditionalConsoleOutputStyles($this->io->getFormatter());
20✔
47
    }
48

49
    public function formatParserResult(
7✔
50
        Result\ParserResult $successful,
51
        Result\ParserResult $failed,
52
        Result\ParserResult $excluded,
53
        ?Time\Duration $duration = null,
54
    ): void {
55
        $sitemaps = [];
7✔
56
        $urlsShown = false;
7✔
57

58
        // Add successful sitemaps
59
        if ($this->io->isVeryVerbose()) {
7✔
60
            foreach ($successful->getSitemaps() as $successfulSitemap) {
3✔
61
                $sitemaps[] = sprintf('<success> DONE </> <href=%1$s>%1$s</>', (string) $successfulSitemap->getUri());
2✔
62
            }
63
        }
64

65
        // Add excluded sitemaps
66
        foreach ($excluded->getSitemaps() as $excludedSitemap) {
7✔
67
            $sitemaps[] = sprintf('<skipped> SKIP </> <href=%1$s>%1$s</>', (string) $excludedSitemap->getUri());
1✔
68
        }
69

70
        // Add failed sitemaps
71
        foreach ($failed->getSitemaps() as $failedSitemap) {
7✔
72
            $sitemaps[] = sprintf('<failure> FAIL </> <href=%1$s>%1$s</>', (string) $failedSitemap->getUri());
1✔
73
        }
74

75
        // Print processed sitemaps
76
        if ([] !== $sitemaps) {
7✔
77
            $this->io->section('Parsed sitemaps');
4✔
78
            $this->io->writeln($sitemaps);
4✔
79
        }
80

81
        // Print parsed URLs
82
        if ($this->io->isDebug() && [] !== $successful->getUrls()) {
7✔
83
            $urlsShown = true;
1✔
84

85
            $this->io->section('Parsed URLs');
1✔
86

87
            foreach ($successful->getUrls() as $successfulUrl) {
1✔
88
                $this->io->writeln(sprintf('<success> DONE </> <href=%1$s>%1$s</>', (string) $successfulUrl));
1✔
89
            }
90
        }
91

92
        // Print excluded URLs
93
        if ([] !== $excluded->getUrls()) {
7✔
94
            $urlsShown = true;
1✔
95

96
            $this->io->section('Excluded URLs');
1✔
97

98
            foreach ($excluded->getUrls() as $excludedUrl) {
1✔
99
                $this->io->writeln(sprintf('<skipped> SKIP </> <href=%1$s>%1$s</>', (string) $excludedUrl));
1✔
100
            }
101
        }
102

103
        // Print duration
104
        if ($this->io->isDebug() && null !== $duration) {
7✔
105
            $this->io->newLine();
1✔
106
            $this->io->writeln(sprintf('Parsing finished in %s', $duration->format()));
1✔
107
        }
108

109
        if ([] !== $sitemaps || $urlsShown) {
7✔
110
            $this->io->newLine();
4✔
111
        }
112
    }
113

114
    public function formatCacheWarmupResult(
9✔
115
        Result\CacheWarmupResult $result,
116
        ?Time\Duration $duration = null,
117
    ): void {
118
        $successfulUrls = $result->getSuccessful();
9✔
119
        $failedUrls = $result->getFailed();
9✔
120
        $urls = [];
9✔
121

122
        // Add successful URLs
123
        if ($this->io->isDebug()) {
9✔
124
            foreach ($successfulUrls as $successfulUrl) {
1✔
125
                $urls[] = sprintf('<success> DONE </> <href=%1$s>%1$s</>', (string) $successfulUrl);
1✔
126
            }
127
        }
128

129
        // Add failed URLs
130
        if ($this->io->isVerbose()) {
9✔
131
            foreach ($failedUrls as $failedUrl) {
2✔
132
                $urls[] = sprintf('<failure> FAIL </> <href=%1$s>%1$s</>', (string) $failedUrl);
1✔
133
            }
134
        }
135

136
        // Prints URLs
137
        if ([] !== $urls) {
9✔
138
            $this->io->section('Crawled URLs');
2✔
139
            $this->io->writeln($urls);
2✔
140
        }
141

142
        // Print crawler results
143
        if ([] !== $successfulUrls) {
9✔
144
            $countSuccessfulUrls = count($successfulUrls);
3✔
145
            $this->io->success(
3✔
146
                sprintf(
3✔
147
                    'Successfully warmed up caches for %d URL%s.',
3✔
148
                    $countSuccessfulUrls,
3✔
149
                    1 === $countSuccessfulUrls ? '' : 's',
3✔
150
                ),
3✔
151
            );
3✔
152
        }
153
        if ([] !== $failedUrls) {
9✔
154
            $countFailedUrls = count($failedUrls);
3✔
155
            $this->io->error(
3✔
156
                sprintf(
3✔
157
                    'Failed to warm up caches for %d URL%s.',
3✔
158
                    $countFailedUrls,
3✔
159
                    1 === $countFailedUrls ? '' : 's',
3✔
160
                ),
3✔
161
            );
3✔
162
        }
163
        if ($result->wasCancelled()) {
9✔
164
            $this->io->warning('Cache warmup was cancelled due to a crawling failure.');
1✔
165
        }
166

167
        // Print duration
168
        if (null !== $duration) {
9✔
169
            $this->io->writeln(
1✔
170
                sprintf(
1✔
171
                    'Crawling %s %s',
1✔
172
                    $result->wasCancelled() ? 'cancelled after' : 'finished in',
1✔
173
                    $duration->format(),
1✔
174
                ),
1✔
175
            );
1✔
176
            $this->io->newLine();
1✔
177
        }
178
    }
179

180
    public function logMessage(string $message, MessageSeverity $severity = MessageSeverity::Info): void
4✔
181
    {
182
        $methodName = $severity->value;
4✔
183

184
        if (method_exists($this->io, $methodName)) {
4✔
185
            call_user_func([$this->io, $methodName], $message);
4✔
186
        }
187
    }
188

189
    public function isVerbose(): bool
×
190
    {
191
        return true;
×
192
    }
193

194
    public static function getType(): string
×
195
    {
196
        return 'text';
×
197
    }
198
}
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

© 2026 Coveralls, Inc