• 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

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
    ) {
30
    }
3✔
31

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

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

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

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

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

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

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

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

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

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

81
        return $result;
1✔
82
    }
83

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

© 2026 Coveralls, Inc