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

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

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

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 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
    ) {}
3✔
22

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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