Processor::run()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 2
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 6
cp 0
crap 2
1
<?php
2
/**
3
 * @author    jan huang <[email protected]>
4
 * @copyright 2017
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      http://www.fast-d.cn/
8
 */
9
10
namespace FastD;
11
12
use FastD\Process\ProcessManager;
13
use Symfony\Component\Console\Input\ArgvInput;
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
/**
18
 * Class Processor.
19
 */
20
class Processor extends Console
21
{
22
    public function registerCommands()
23
    {
24
        $command = new ProcessManager();
25
26
        $this->add($command);
27
28
        $path = app()->getPath().'/config/process.php';
29
30
        if (file_exists($path)) {
31
            config()->set('processes', include $path);
32
        }
33
    }
34
35
    /**
36
     * @param InputInterface|null  $input
37
     * @param OutputInterface|null $output
38
     *
39
     * @return int
40
     */
41 View Code Duplication
    public function run(InputInterface $input = null, OutputInterface $output = null)
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...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $argv = $_SERVER['argv'];
44
        $script = array_shift($argv);
45
        array_unshift($argv, 'process');
46
        array_unshift($argv, $script);
47
48
        return parent::run(new ArgvInput($argv), $output);
49
    }
50
}
51