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

tempestphp / tempest-framework / 12021213285

26 Nov 2024 12:18AM UTC coverage: 77.441% (-2.0%) from 79.441%
12021213285

Pull #754

github

web-flow
Merge 46eda39bc into cc0c7eea3
Pull Request #754: feat(framework): overhaul console interactions

734 of 1174 new or added lines in 55 files covered. (62.52%)

54 existing lines in 12 files now uncovered.

8239 of 10639 relevant lines covered (77.44%)

60.83 hits per line

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

95.24
/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\Console;
8
use Tempest\Console\StaticConsoleComponent;
9

10
final readonly class StaticSingleChoiceComponent implements StaticConsoleComponent
11
{
12
    public function __construct(
22✔
13
        public string $label,
14
        public array $options,
15
        public mixed $default = null,
16
    ) {
17
    }
22✔
18

19
    public function render(Console $console): ?string
22✔
20
    {
21
        if (! $console->supportsPrompting()) {
22✔
22
            return $this->default;
1✔
23
        }
24

25
        $console->write("<h2>{$this->label}</h2> ");
21✔
26

27
        $parsedOptions = [];
21✔
28

29
        foreach ($this->options as $key => $option) {
21✔
30
            $key = $key === $this->default
21✔
NEW
31
                ? "<em><strong>{$key}</strong></em>"
×
32
                : $key;
21✔
33

34
            $parsedOptions[$key] = "- [{$key}] {$option}";
21✔
35
        }
36

37
        $console->write(PHP_EOL . implode(PHP_EOL, $parsedOptions) . PHP_EOL);
21✔
38

39
        $answer = trim($console->readln());
21✔
40

41
        if (! $answer && $this->default) {
15✔
42
            return $this->options[$this->default] ?? $this->default;
6✔
43
        }
44

45
        if (array_is_list($this->options) && in_array($answer, $this->options)) {
9✔
46
            return $answer;
8✔
47
        }
48

49
        if (array_key_exists($answer, $this->options)) {
2✔
50
            return $this->options[$answer];
1✔
51
        }
52

53
        return $this->render($console);
1✔
54
    }
55
}
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