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

Countdown   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A from() 0 23 3
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