ShellHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 10 2
A isCygwin() 0 8 1
A progress() 0 9 2
A progressEnd() 0 4 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
}