Passed
Push — master ( f8a196...66e67e )
by Evgenii
01:52
created

Subcommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 18
c 1
b 0
f 0
dl 0
loc 73
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A compileEnvironmentVariables() 0 10 1
A runProcess() 0 15 1
1
<?php
2
3
namespace Helick\LocalServer\Subcommands;
4
5
use Symfony\Component\Console\Application;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Output\OutputInterface;
8
use Symfony\Component\Process\Process;
9
10
abstract class Subcommand
11
{
12
    /**
13
     * The subcommand working directory.
14
     *
15
     * @var string
16
     */
17
    const CWD = 'vendor/helick/local-server/docker';
18
19
    /**
20
     * The application instance.
21
     *
22
     * @var Application
23
     */
24
    protected $application;
25
26
    /**
27
     * Create a subcommand instance.
28
     *
29
     * @param Application $application
30
     *
31
     * @return void
32
     */
33
    public function __construct(Application $application)
34
    {
35
        $this->application = $application;
36
    }
37
38
    /**
39
     * Invoke the subcommand.
40
     *
41
     * @param InputInterface  $input
42
     * @param OutputInterface $output
43
     *
44
     * @return void
45
     */
46
    abstract public function __invoke(InputInterface $input, OutputInterface $output): void;
47
48
    /**
49
     * @param string $command
50
     *
51
     * @return Process
52
     */
53
    protected function runProcess(string $command): Process
54
    {
55
        $process = new Process(
56
            $command,
0 ignored issues
show
Bug introduced by
$command of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

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

56
            /** @scrutinizer ignore-type */ $command,
Loading history...
57
            static::CWD,
58
            $this->compileEnvironmentVariables()
59
        );
60
61
        $process->setTimeout(0);
62
63
        $process->run(function ($_, $buffer) {
64
            echo $buffer;
65
        });
66
67
        return $process;
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    protected function compileEnvironmentVariables(): array
74
    {
75
        return [
76
            'COMPOSE_PROJECT_NAME' => basename(getcwd()),
77
            'VOLUME'               => getcwd(),
78
            'PATH'                 => getenv('PATH'),
79
80
            // Windows-specific
81
            'TEMP'                 => getenv('TEMP'),
82
            'SystemRoot'           => getenv('SystemRoot'),
83
        ];
84
    }
85
}
86