ProcessCommand::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
namespace Magestead\Command;
3
4
use Symfony\Component\Process\Process;
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
/**
8
 * Class ProcessCommand
9
 * @package Magestead\Command
10
 */
11
class ProcessCommand
12
{
13
    /**
14
     * ProcessCommand constructor.
15
     * @param $command
16
     * @param $projectPath
17
     * @param OutputInterface $output
18
     */
19
    public function __construct($command, $projectPath, OutputInterface $output)
20
    {
21
        $this->run($command, $projectPath, $output);
22
    }
23
24
    /**
25
     * @param $command
26
     * @param $projectPath
27
     * @param OutputInterface $output
28
     */
29
    protected function run($command, $projectPath, OutputInterface $output)
0 ignored issues
show
Coding Style introduced by
run uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
run uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
30
    {
31
        $process = new Process($command, $projectPath, array_merge($_SERVER, $_ENV), null, null);
32
33
        $process->run(function ($type, $line) use ($output) {
34
            $output->write($line);
35
        });
36
    }
37
}