• 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

88.57
/src/Tempest/Console/src/Components/Interactive/ProgressBarComponent.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Console\Components\Interactive;
6

7
use Closure;
8
use Generator;
9
use Tempest\Console\Components\Concerns\HasErrors;
10
use Tempest\Console\Components\Concerns\HasState;
11
use Tempest\Console\Components\Concerns\RendersControls;
12
use Tempest\Console\Components\Static\StaticProgressBarComponent;
13
use Tempest\Console\HasStaticComponent;
14
use Tempest\Console\InteractiveConsoleComponent;
15
use Tempest\Console\StaticConsoleComponent;
16
use Tempest\Console\Terminal\Terminal;
17

18
final class ProgressBarComponent implements InteractiveConsoleComponent, HasStaticComponent
19
{
20
    use HasErrors;
21
    use HasState;
22
    use RendersControls;
23

24
    public function __construct(
3✔
25
        private readonly iterable $data,
26
        private readonly Closure $handler,
27
        /** @var null|Closure(int $step, int $count): string $format */
28
        private readonly ?Closure $format = null,
29
    ) {}
3✔
30

31
    public StaticConsoleComponent $staticComponent {
32
        get => new StaticProgressBarComponent(
33
            data: $this->data,
34
            handler: $this->handler,
35
            format: $this->format,
36
        );
37
    }
38

39
    public function render(Terminal $terminal): Generator
2✔
40
    {
41
        $result = [];
2✔
42

43
        $count = iterator_count($this->data);
2✔
44
        $step = 1;
2✔
45

46
        $format = $this->format ?? function (int $step, int $count): string {
2✔
47
            $width = 30;
1✔
48

49
            $progress = (int) round(($step / $count) * $width);
1✔
50

51
            if ($step === $count) {
1✔
52
                $bar = sprintf(
1✔
53
                    '[%s]',
1✔
54
                    str_repeat('=', $width),
1✔
55
                );
1✔
56
            } else {
57
                $bar = sprintf(
1✔
58
                    '[%s>%s]',
1✔
59
                    str_repeat('=', max(0, $progress)),
1✔
60
                    str_repeat(' ', $width - $progress),
1✔
61
                );
1✔
62
            }
63

64
            return sprintf(
1✔
65
                '%s (%s/%s)',
1✔
66
                $bar,
1✔
67
                $step,
1✔
68
                $count,
1✔
69
            );
1✔
70
        };
1✔
71

72
        foreach ($this->data as $item) {
2✔
73
            yield $format($step, $count);
2✔
74

75
            $result[] = ($this->handler)($item);
1✔
76

77
            $step += 1;
1✔
78
        }
79

80
        return $result;
1✔
81
    }
82

UNCOV
83
    private function getControls(): array
×
84
    {
UNCOV
85
        return [
×
86
            'ctrl+c' => 'cancel',
×
87
        ];
×
88
    }
89
}
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