Test Failed
Push — feat/cache-warming ( 037623...493f4d )
by Chema
04:16
created

CacheWarmOutputFormatter   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 92
rs 10
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A writeCacheCleared() 0 4 1
A writeClassSkipped() 0 3 1
A writeClassFailed() 0 3 1
A writeHeader() 0 6 1
A __construct() 0 3 1
A writeEmptyLine() 0 3 1
A writeModuleDiscoveryWarning() 0 4 1
A writeCacheInfo() 0 5 1
A writeModulesFound() 0 4 1
A writeSummary() 0 16 1
A writeModuleName() 0 3 1
A writeCacheWarning() 0 6 1
A writeClassResolved() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Console\Application\CacheWarm;
6
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
use function count;
10
use function sprintf;
11
use function str_repeat;
12
13
final class CacheWarmOutputFormatter
14
{
15
    public function __construct(
16
        private readonly OutputInterface $output,
17
    ) {
18
    }
19
20
    public function writeHeader(): void
21
    {
22
        $this->output->writeln('');
23
        $this->output->writeln('<info>Warming Gacela cache...</info>');
24
        $this->output->writeln('<info>' . str_repeat('=', 60) . '</info>');
25
        $this->output->writeln('');
26
    }
27
28
    public function writeCacheCleared(): void
29
    {
30
        $this->output->writeln('<fg=yellow>Cleared existing cache</>');
31
        $this->output->writeln('');
32
    }
33
34
    public function writeModuleDiscoveryWarning(string $errorMessage): void
35
    {
36
        $this->output->writeln('<fg=yellow>Warning: Some modules could not be discovered due to errors</>');
37
        $this->output->writeln(sprintf('  Error: %s', $errorMessage));
38
    }
39
40
    /**
41
     * @param list<mixed> $modules
42
     */
43
    public function writeModulesFound(array $modules): void
44
    {
45
        $this->output->writeln(sprintf('<fg=cyan>Found %d modules</>', count($modules)));
46
        $this->output->writeln('');
47
    }
48
49
    public function writeModuleName(string $moduleName): void
50
    {
51
        $this->output->writeln(sprintf('<comment>Processing:</> %s', $moduleName));
52
    }
53
54
    public function writeClassResolved(string $type, string $className): void
55
    {
56
        $this->output->writeln(sprintf('  <fg=green>✓ Resolved %s:</> %s', $type, $className));
57
    }
58
59
    public function writeClassSkipped(string $type, string $className): void
60
    {
61
        $this->output->writeln(sprintf('  <fg=yellow>⚠ Skipped %s:</> %s (class not found)', $type, $className));
62
    }
63
64
    public function writeClassFailed(string $type, string $className, string $errorMessage): void
65
    {
66
        $this->output->writeln(sprintf('  <fg=red>✗ Failed %s:</> %s (%s)', $type, $className, $errorMessage));
67
    }
68
69
    public function writeEmptyLine(): void
70
    {
71
        $this->output->writeln('');
72
    }
73
74
    public function writeSummary(
75
        int $modulesCount,
76
        int $resolvedCount,
77
        int $skippedCount,
78
        string $timeTaken,
79
        string $memoryUsed,
80
    ): void {
81
        $this->output->writeln('<info>' . str_repeat('=', 60) . '</info>');
82
        $this->output->writeln('<info>Cache warming complete!</info>');
83
        $this->output->writeln('');
84
        $this->output->writeln(sprintf('<fg=cyan>Modules processed:</> %d', $modulesCount));
85
        $this->output->writeln(sprintf('<fg=cyan>Classes resolved:</> %d', $resolvedCount));
86
        $this->output->writeln(sprintf('<fg=cyan>Classes skipped:</> %d', $skippedCount));
87
        $this->output->writeln(sprintf('<fg=cyan>Time taken:</> %s', $timeTaken));
88
        $this->output->writeln(sprintf('<fg=cyan>Memory used:</> %s', $memoryUsed));
89
        $this->output->writeln('');
90
    }
91
92
    public function writeCacheInfo(string $cacheFile, string $cacheSize): void
93
    {
94
        $this->output->writeln(sprintf('<fg=cyan>Cache file:</> %s', $cacheFile));
95
        $this->output->writeln(sprintf('<fg=cyan>Cache size:</> %s', $cacheSize));
96
        $this->output->writeln('');
97
    }
98
99
    public function writeCacheWarning(): void
100
    {
101
        $this->output->writeln('<fg=yellow>Warning: Cache file was not created. File caching might be disabled.</>');
102
        $this->output->writeln('<comment>Enable file caching in your gacela.php configuration:</>');
103
        $this->output->writeln('<comment>  $config->enableFileCache();</>');
104
        $this->output->writeln('');
105
    }
106
}
107