• 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

95.12
/src/Tempest/Console/src/Components/Static/StaticSingleChoiceComponent.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Console\Components\Static;
6

7
use Tempest\Console\Components\Option;
8
use Tempest\Console\Components\OptionCollection;
9
use Tempest\Console\Console;
10
use Tempest\Console\StaticConsoleComponent;
11
use UnitEnum;
12

13
use function Tempest\Support\str;
14

15
final readonly class StaticSingleChoiceComponent implements StaticConsoleComponent
16
{
17
    private OptionCollection $options;
18

19
    public function __construct(
29✔
20
        public string $label,
21
        iterable $options,
22
        public null|int|UnitEnum|string $default = null,
23
    ) {
24
        $this->options = new OptionCollection($options);
29✔
25
    }
26

27
    public function render(Console $console): null|int|UnitEnum|string
29✔
28
    {
29
        if (! $console->supportsPrompting()) {
29✔
30
            return $this->default;
1✔
31
        }
32

33
        $console->write("<style='bold fg-blue'>{$this->label}</style> ");
28✔
34

35
        $prompt = $this->options
28✔
36
            ->getOptions()
28✔
37
            ->map(
28✔
38
                fn (Option $option, int $index) => str($index)
28✔
39
                    ->when(
28✔
40
                        condition: $option->key === $this->default || $option->value === $this->default,
28✔
41
                        callback: fn ($s) => $s->wrap('<style="fg-blue">', '</style>'),
28✔
42
                    )
28✔
43
                    ->wrap('[', ']')
28✔
44
                    ->prepend('- ')
28✔
45
                    ->append(' ', (string) $option->displayValue)
28✔
46
                    ->toString(),
28✔
47
            )
28✔
48
            ->implode(PHP_EOL)
28✔
49
            ->toString();
28✔
50

51
        $console->write(PHP_EOL . $prompt . PHP_EOL);
28✔
52

53
        $answer = trim($console->readln());
28✔
54

55
        if ($answer === '' && $this->default) {
23✔
56
            return $this->default;
7✔
57
        }
58

59
        $selectedOption = $this->options
16✔
60
            ->getOptions()
16✔
61
            ->first(function (Option $option, int $index) use ($answer) {
16✔
62
                if ($answer === $option->displayValue) {
16✔
63
                    return true;
9✔
64
                }
65

66
                if ($answer === $option->value) {
12✔
UNCOV
67
                    return true;
×
68
                }
69

70
                if ($this->options->getOptions()->isList() && $answer === ((string) $index)) {
12✔
71
                    return true;
7✔
72
                }
73

74
                if ($this->options->getOptions()->isList() && $answer === ((string) $option->key)) {
10✔
UNCOV
75
                    return true;
×
76
                }
77

78
                return false;
10✔
79
            });
16✔
80

81
        if ($selectedOption !== null) {
16✔
82
            return $selectedOption->value;
16✔
83
        }
84

85
        return $this->render($console);
1✔
86
    }
87
}
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