Completed
Push — countdown ( 5f4254 )
by Craig
31:51
created

Countdown::from()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace League\CLImate\TerminalObject\Dynamic;
4
5
final class Countdown extends DynamicTerminalObject
6
{
7
    /** @var string */
8
    private $label = "";
9
10
11
    /**
12
     * @param string $label
13
     */
14
    public function __construct(string $label = "Starting in... ")
15
    {
16
        $this->label = $label;
17
    }
18
19
20
    /**
21
     * @param int $from
22
     */
23
    public function from(int $from): void
24
    {
25
        $firstLine = true;
26
        $i = $from;
27
        while ($i-- > 0) {
28
29
            $content = "";
30
31
            if ($firstLine) {
32
                $firstLine = false;
33
            } else {
34
                $content .= $this->util->cursor->up(1);
35
                $content .= $this->util->cursor->startOfCurrentLine();
36
                $content .= $this->util->cursor->deleteCurrentLine();
37
            }
38
39
            $content .= $this->label;
40
            $content .= $i;
41
42
            $this->output->write($this->parser->apply($content));
43
            sleep(1);
44
        }
45
    }
46
}
47