Client::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 2016
5
 *
6
 * @see      https://www.github.com/janhuang
7
 * @see      https://fastdlabs.com
8
 */
9
10
namespace FastD;
11
12
use Symfony\Component\Console\Input\ArgvInput;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Output\OutputInterface;
15
16
/**
17
 * Class Client.
18
 */
19
class Client extends Console
20
{
21
    public function __construct(Application $app)
22
    {
23
        parent::__construct($app);
24
25
        $this->add(new \FastD\Console\Client());
26
    }
27
28
    /**
29
     * @param InputInterface|null  $input
30
     * @param OutputInterface|null $output
31
     *
32
     * @return int
33
     */
34 View Code Duplication
    public function run(InputInterface $input = null, OutputInterface $output = null)
0 ignored issues
show
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...
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...
35
    {
36
        $argv = $_SERVER['argv'];
37
        $script = array_shift($argv);
38
        array_unshift($argv, 'client');
39
        array_unshift($argv, $script);
40
41
        return parent::run(new ArgvInput($argv), $output);
42
    }
43
}
44