Processor   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 29.03 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 9
loc 31
rs 10
c 0
b 0
f 0
ccs 0
cts 14
cp 0
wmc 3
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerCommands() 0 12 2
A run() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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