ShellHelper::progress()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php namespace Tequilarapido\Helpers;
2
3
use Symfony\Component\Console\Output\OutputInterface;
4
use Symfony\Component\Process\Process;
5
6
class ShellHelper
7
{
8
    const CHAR_SAMELINE = "\x0D";
9
10
    /**
11
     * Progress cursors
12
     * @var array
13
     */
14
    static protected $cursors = array('-', '\\', '|', '/');
15
16
    /**
17
     * @param $cmd
18
     * @return Process
19
     */
20
    public static function run($cmd)
21
    {
22
        if (static::isCygwin()) {
23
            $cmd = "C:\cygwin\bin\bash.exe --login  -c '" . $cmd . "'";
24
        }
25
26
        $process = new Process($cmd);
27
        $process->run();
28
        return $process;
29
    }
30
31
    public static function isCygwin()
32
    {
33
        $cmd = "cygpath -w ~";
34
        $process = new Process($cmd);
35
        $process->run();
36
37
        return $process->isSuccessful();
38
    }
39
40
    public static function progress(OutputInterface $output)
41
    {
42
        $char = current(static::$cursors);
43
        $output->write(static::CHAR_SAMELINE . $char);
44
45
        if (false === next(static::$cursors)) {
46
            reset(static::$cursors);
47
        }
48
    }
49
50
    public static function progressEnd(OutputInterface $output)
51
    {
52
        $output->write(static::CHAR_SAMELINE . ' ');
53
    }
54
55
}