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

Cli::currentWorkingDirectory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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