Completed
Push — master ( 03739e...51f188 )
by Michał
14:48 queued 08:49
created

Animation::setWaitTime()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 3
eloc 11
c 2
b 0
f 1
nc 3
nop 1
dl 0
loc 18
rs 9.9
ccs 0
cts 12
cp 0
crap 12
1
<?php
2
3
namespace BlueConsole;
4
5
class Animation
6
{
7
    /**
8
     * @var \DateInterval
9
     */
10
    protected $interval;
11
12
    public function __construct(int $steps = 6, string $cursor = '*')
13
    {
14
        $counter = 0;
15
        $forward = true;
16
        $before = 0;
17
        $after = $steps - \strlen($cursor);
18
19
        echo "\n";
20
21
        while (true) {
22
            echo '[';
23
24
            for ($i = 1; $i <= $before; $i++) {
25
                echo ' ';
26
            }
27
28
            echo $cursor;
29
30
            for ($i = 0; $i <= $after; $i++) {
31
                echo ' ';
32
            }
33
34
            echo ']';
35
            echo "\r";
36
37
            $counter++;
38
39
            if ($forward) {
40
                $before++;
41
                $after--;
42
            } else {
43
                $before--;
44
                $after++;
45
            }
46
47
            if ($counter === ($steps - (\strlen($cursor) -1))) {
48
                $counter = 0;
49
                $forward = !$forward;
0 ignored issues
show
introduced by
The condition $forward is always true.
Loading history...
50
            }
51
52
            sleep(1);
53
        }
54
    }
55
56
    public function setWaitTime(\DateInterval $dateInterval)
57
    {
58
        //        $interval = new \DateInterval('PT10S');
59
        $dateInterval->invert = true;
0 ignored issues
show
Documentation Bug introduced by
The property $invert was declared of type integer, but true is of type true. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
60
        //dump($interval);
61
62
        $d1 = new \DateTime();
63
        while (true) {
64
            $d2 = new \DateTime();
65
            $d2->add($dateInterval);
66
67
            $iv = $d2->diff($d1);
68
            dump($iv->s);
69
            if ($iv->s === 0) {
70
                echo "end\n";
71
                exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
72
            }
73
            sleep(1);
74
        }
75
    }
76
77
    public function setMessage(string $message)
0 ignored issues
show
Unused Code introduced by
The parameter $message is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

77
    public function setMessage(/** @scrutinizer ignore-unused */ string $message)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79
        
80
    }
81
82
    public function run($process)
0 ignored issues
show
Unused Code introduced by
The parameter $process is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

82
    public function run(/** @scrutinizer ignore-unused */ $process)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
    {
84
        //display message with animation
85
        //execute external process
86
        //wait and display animation
87
        //process ended -> display message and go fodder
88
    }
89
90
    protected function displayAnimation()
91
    {
92
        $counter = 0;
93
        $forward = true;
94
        $before = 0;
95
        $after = $steps - \strlen($cursor);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $steps seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $cursor seems to be never defined.
Loading history...
96
97
        while (true) {
98
            echo '[';
99
100
            for ($i = 1; $i <= $before; $i++) {
101
                echo ' ';
102
            }
103
104
            echo $cursor;
105
106
            for ($i = 0; $i <= $after; $i++) {
107
                echo ' ';
108
            }
109
110
            echo ']';
111
            echo "\r";
112
113
            $counter++;
114
115
            if ($forward) {
116
                $before++;
117
                $after--;
118
            } else {
119
                $before--;
120
                $after++;
121
            }
122
123
            if ($counter === ($steps - (\strlen($cursor) -1))) {
124
                $counter = 0;
125
                $forward = !$forward;
0 ignored issues
show
introduced by
The condition $forward is always true.
Loading history...
126
            }
127
128
            sleep(1);
129
        }
130
    }
131
132
    protected function executeProcess()
133
    {
134
        
135
    }
136
}
137