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

JBZoo / Cli / 5838584207

pending completion
5838584207

push

github

web-flow
Predefined output formats - ELK, cron. New demo and docs. (#15)

745 of 745 new or added lines in 16 files covered. (100.0%)

899 of 1078 relevant lines covered (83.4%)

136.5 hits per line

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

82.61
/src/ProgressBars/AbstractProgressBar.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Cli.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Cli
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\Cli\ProgressBars;
18

19
use JBZoo\Cli\OutputMods\AbstractOutputMode;
20

21
abstract class AbstractProgressBar
22
{
23
    protected AbstractOutputMode $outputMode;
24

25
    protected ?\Closure $callback = null;
26

27
    protected bool $throwBatchException = true;
28

29
    protected int      $max         = 0;
30
    protected iterable $list        = [];
31
    protected string   $title       = '';
32
    protected int      $nestedLevel = 0;
33

34
    protected ?\Closure $callbackOnStart  = null;
35
    protected ?\Closure $callbackOnFinish = null;
36

37
    abstract public function execute(): bool;
38

39
    public function __construct(AbstractOutputMode $outputMode)
40
    {
41
        $this->outputMode = $outputMode;
168✔
42
    }
43

44
    public function setTitle(string $title): self
45
    {
46
        $this->title = $title;
168✔
47

48
        return $this;
168✔
49
    }
50

51
    public function setList(iterable $list): self
52
    {
53
        $this->list = $list;
60✔
54

55
        if ($list instanceof \Countable) {
60✔
56
            $this->max = \count($list);
16✔
57
        } elseif (\is_array($list)) {
44✔
58
            $this->max = \count($list);
44✔
59
        }
60

61
        return $this;
60✔
62
    }
63

64
    public function setCallback(\Closure $callback): self
65
    {
66
        $this->callback = $callback;
168✔
67

68
        return $this;
168✔
69
    }
70

71
    public function setThrowBatchException(bool $throwBatchException): self
72
    {
73
        $this->throwBatchException = $throwBatchException;
168✔
74

75
        return $this;
168✔
76
    }
77

78
    public function setMax(int $max): self
79
    {
80
        $this->max  = $max;
112✔
81
        $this->list = \range(0, $max - 1);
112✔
82

83
        return $this;
112✔
84
    }
85

86
    public function onStart(\Closure $callback): self
87
    {
88
        $this->callbackOnStart = $callback;
×
89

90
        return $this;
×
91
    }
92

93
    public function onFinish(\Closure $callback): self
94
    {
95
        $this->callbackOnFinish = $callback;
×
96

97
        return $this;
×
98
    }
99

100
    public function setNextedLevel(int $nestedLevel): self
101
    {
102
        $this->nestedLevel = $nestedLevel;
168✔
103

104
        return $this;
168✔
105
    }
106

107
    public function getNextedLevel(): int
108
    {
109
        return $this->nestedLevel;
168✔
110
    }
111
}
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