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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

2 of 2 new or added lines in 2 files covered. (100.0%)

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

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

26.53
/src/Tempest/Console/src/Actions/RenderConsoleCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Console\Actions;
6

7
use BackedEnum;
8
use Tempest\Console\Console;
9
use Tempest\Console\ConsoleCommand;
10
use Tempest\Console\Input\ConsoleArgumentDefinition;
11

12
use function Tempest\Support\str;
13

14
final readonly class RenderConsoleCommand
15
{
16
    public function __construct(
3✔
17
        private Console $console,
18
        private ?int $longestCommandName = null,
19
        private bool $renderArguments = false,
20
        private bool $renderDescription = true,
21
    ) {
22
    }
3✔
23

24
    public function __invoke(ConsoleCommand $consoleCommand): void
3✔
25
    {
26
        $parts = [$this->renderName($consoleCommand)];
3✔
27

28
        if ($this->renderArguments) {
3✔
UNCOV
29
            foreach ($consoleCommand->getArgumentDefinitions() as $argument) {
×
UNCOV
30
                $parts[] = '<style="fg-gray">' . $this->renderArgument($argument) . '</style>';
×
31
            }
32
        }
33

34
        if ($this->renderDescription) {
3✔
35
            if ($consoleCommand->description !== null && $consoleCommand->description !== '') {
3✔
36
                $parts[] = "<style='dim'>{$consoleCommand->description}</style>";
3✔
37
            }
38
        }
39

40
        $this->console->writeln(implode(' ', $parts));
3✔
41
    }
42

43
    private function renderName(ConsoleCommand $consoleCommand): string
3✔
44
    {
45
        return str($consoleCommand->getName())
3✔
46
            ->alignRight($this->longestCommandName, padding: $this->longestCommandName ? 2 : 0)
3✔
47
            ->toString();
3✔
48
    }
49

UNCOV
50
    private function renderArgument(ConsoleArgumentDefinition $argument): string
×
51
    {
UNCOV
52
        if ($argument->isBackedEnum()) {
×
UNCOV
53
            return $this->renderEnumArgument($argument);
×
54
        }
55

UNCOV
56
        $formattedArgumentName = match ($argument->type) {
×
UNCOV
57
            'bool' => "--{$argument->name}",
×
UNCOV
58
            default => $argument->name,
×
UNCOV
59
        };
×
60

UNCOV
61
        $formattedArgumentName = str($formattedArgumentName)->wrap('<style="fg-blue">', '</style>');
×
62

UNCOV
63
        if (! $argument->hasDefault) {
×
UNCOV
64
            return $formattedArgumentName->wrap('<style="fg-gray dim"><</style>', '<style="fg-gray dim">></style>')->toString();
×
65
        }
66

UNCOV
67
        $defaultValue = match (true) {
×
UNCOV
68
            $argument->default === true => 'true',
×
UNCOV
69
            $argument->default === false => 'false',
×
UNCOV
70
            is_null($argument->default) => 'null',
×
UNCOV
71
            is_array($argument->default) => 'array',
×
UNCOV
72
            default => "{$argument->default}",
×
UNCOV
73
        };
×
74

UNCOV
75
        return str()
×
UNCOV
76
            ->append(str('[')->wrap('<style="fg-gray dim">', '</style>'))
×
UNCOV
77
            ->append($formattedArgumentName)
×
UNCOV
78
            ->append(str('=')->wrap('<style="fg-gray dim">', '</style>'))
×
UNCOV
79
            ->append(str($defaultValue)->wrap('<style="fg-gray">', '</style>'))
×
UNCOV
80
            ->append(str(']')->wrap('<style="fg-gray dim">', '</style>'))
×
UNCOV
81
            ->toString();
×
82
    }
83

UNCOV
84
    private function renderEnumArgument(ConsoleArgumentDefinition $argument): string
×
85
    {
UNCOV
86
        $parts = array_map(
×
UNCOV
87
            callback: fn (BackedEnum $case) => $case->value,
×
UNCOV
88
            array: $argument->type::cases(),
×
UNCOV
89
        );
×
90

UNCOV
91
        $partsAsString = ' {<style="fg-blue">' . implode('|', $parts) . '</style>}';
×
UNCOV
92
        $line = "<style=\"fg-blue\">{$argument->name}</style>";
×
93

UNCOV
94
        if ($argument->hasDefault) {
×
UNCOV
95
            return "[{$line}={$argument->default->value}{$partsAsString}]";
×
96
        }
97

UNCOV
98
        return "<{$line}{$partsAsString}>";
×
99
    }
100
}
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