Test Failed
Branch feature__set_up_scrutinizer (ea6624)
by Robin
06:04 queued 02:46
created

Cli   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 63
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A passthru() 0 11 2
A currentWorkingDirectory() 0 3 1
A execRealTime() 0 10 2
A exec() 0 6 1
1
<?php
2
3
namespace App\Support\Console;
4
5
use App\Support\Contracts\Cli as CliContract;
6
use Symfony\Component\Process\Exception\ProcessFailedException;
7
use Symfony\Component\Process\Process;
8
9
class Cli implements CliContract
10
{
11
    /**
12
     * Execute a command.
13
     *
14
     * @param string $command
15
     * @return string
16
     */
17
    public function exec($command)
18
    {
19
        $process = new Process($command);
20
        $process->run();
21
22
        return $process->getOutput();
23
    }
24
25
    /**
26
     * Execute a command in real time.
27
     *
28
     * @param string $command
29
     * @return string
30
     */
31
    public function execRealTime($command)
32
    {
33
        $process = new Process($command);
34
35
        try {
36
            $process->mustRun(function ($type, $buffer) {
37
                echo $buffer;
38
            });
39
        } catch (ProcessFailedException $e) {
40
            echo $e->getMessage();
41
        }
42
    }
43
44
    /**
45
     * Execute a command and allow the user to interact with it.
46
     *
47
     * @param string $command
48
     * @return void
49
     */
50
    public function passthru($command)
51
    {
52
        $process = new Process($command);
53
54
        try {
55
            $process->setTty(true);
56
            $process->mustRun(function ($type, $buffer) {
57
                echo $buffer;
58
            });
59
        } catch (ProcessFailedException $e) {
60
            echo $e->getMessage();
61
        }
62
    }
63
64
    /**
65
     * Return the current working directory
66
     *
67
     * @return string
68
     */
69
    public function currentWorkingDirectory()
70
    {
71
        return getcwd();
72
    }
73
}
74