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

tempestphp / tempest-framework / 14161923512

30 Mar 2025 01:41PM UTC coverage: 80.964% (+0.2%) from 80.716%
14161923512

push

github

web-flow
ci: prevent coveralls failures from failing tests (#1104)

11058 of 13658 relevant lines covered (80.96%)

100.68 hits per line

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

84.78
/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(
111✔
26
        private Console $console,
27
        private ExecuteConsoleCommand $executeConsoleCommand,
28
    ) {}
111✔
29

30
    public function __invoke(Invocation $invocation, ConsoleMiddlewareCallable $next): ExitCode|int
111✔
31
    {
32
        try {
33
            return $next($invocation);
111✔
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
        if (! $this->console->supportsPrompting()) {
4✔
47
            throw $exception;
×
48
        }
49

50
        foreach ($exception->invalidArguments as $argument) {
4✔
51
            $isEnum = is_a($argument->type, BackedEnum::class, allow_string: true);
4✔
52
            $name = str($argument->name)->snake(' ')->upperFirst()->toString();
4✔
53

54
            if ($argument->type === 'bool') {
4✔
55
                $value = $this->console->confirm(
×
56
                    question: $name,
×
57
                    default: $argument->default ?? false,
×
58
                );
×
59
            } else {
60
                $value = $this->console->ask(
4✔
61
                    question: $name,
4✔
62
                    default: $argument->default,
4✔
63
                    hint: $argument->help ?: $argument->description,
4✔
64
                    options: match (true) {
4✔
65
                        $isEnum => $argument->type::cases(),
4✔
66
                        default => null,
4✔
67
                    },
4✔
68
                    validation: array_filter([
4✔
69
                        $isEnum
4✔
70
                            ? new Enum($argument->type)
2✔
71
                            : new NotEmpty(),
4✔
72
                        match ($argument->type) {
4✔
73
                            'bool' => new IsBoolean(),
×
74
                            'int' => new Numeric(),
×
75
                            default => null,
4✔
76
                        },
4✔
77
                    ]),
4✔
78
                );
4✔
79
            }
80

81
            $invocation->argumentBag->add(new ConsoleInputArgument(
3✔
82
                name: $argument->name,
3✔
83
                position: $argument->position,
3✔
84
                value: $value,
3✔
85
            ));
3✔
86
        }
87

88
        return ($this->executeConsoleCommand)($invocation->consoleCommand->getName());
3✔
89
    }
90
}
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

© 2025 Coveralls, Inc