• 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

94.29
/src/Tempest/Console/src/Middleware/InvalidCommandMiddleware.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Console\Middleware;
6

7
use BackedEnum;
8
use Tempest\Console\Actions\ExecuteConsoleCommand;
9
use Tempest\Console\Console;
10
use Tempest\Console\ConsoleMiddleware;
11
use Tempest\Console\ConsoleMiddlewareCallable;
12
use Tempest\Console\Exceptions\InvalidCommandException;
13
use Tempest\Console\ExitCode;
14
use Tempest\Console\Initializers\Invocation;
15
use Tempest\Console\Input\ConsoleInputArgument;
16
use Tempest\Validation\Rules\Enum;
17
use Tempest\Validation\Rules\IsBoolean;
18
use Tempest\Validation\Rules\NotEmpty;
19
use Tempest\Validation\Rules\Numeric;
20

21
use function Tempest\Support\str;
22

23
final readonly class InvalidCommandMiddleware implements ConsoleMiddleware
24
{
25
    public function __construct(
99✔
26
        private Console $console,
27
        private ExecuteConsoleCommand $executeConsoleCommand,
28
    ) {}
99✔
29

30
    public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int
99✔
31
    {
32
        try {
33
            return $next($invocation);
99✔
34
        } catch (InvalidCommandException $invalidCommandException) {
4✔
35
            return $this->retry($invocation, $invalidCommandException);
4✔
36
        }
37
    }
38

39
    private function retry(Invocation $invocation, InvalidCommandException $exception): ExitCode|int
4✔
40
    {
41
        $this->console->header(
4✔
42
            header: $invocation->consoleCommand->getName(),
4✔
43
            subheader: $invocation->consoleCommand->description,
4✔
44
        );
4✔
45

46
        foreach ($exception->invalidArguments as $argument) {
4✔
47
            $isEnum = is_a($argument->type, BackedEnum::class, allow_string: true);
4✔
48

49
            $value = $this->console->ask(
4✔
50
                question: str($argument->name)->snake(' ')->upperFirst()->toString(),
4✔
51
                options: $isEnum ? $argument->type::cases() : null,
4✔
52
                default: $argument->default,
4✔
53
                hint: $argument->help ?? $argument->description,
4✔
54
                validation: array_filter([
4✔
55
                    $isEnum
4✔
56
                        ? new Enum($argument->type)
2✔
57
                        : new NotEmpty(),
4✔
58
                    match ($argument->type) {
4✔
UNCOV
59
                        'bool' => new IsBoolean(),
×
60
                        'int' => new Numeric(),
×
61
                        default => null,
4✔
62
                    },
4✔
63
                ]),
4✔
64
            );
4✔
65

66
            $invocation->argumentBag->add(new ConsoleInputArgument(
3✔
67
                name: $argument->name,
3✔
68
                position: $argument->position,
3✔
69
                value: $value,
3✔
70
            ));
3✔
71
        }
72

73
        return ($this->executeConsoleCommand)($invocation->consoleCommand->getName());
3✔
74
    }
75
}
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