GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push β€” master ( 3ec9bd...fb02b8 )
by cao
08:48
created

Console::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: caoyangmin
5
 * Date: 2018/6/14
6
 * Time: δΈ‹εˆ6:11
7
 */
8
9
namespace PhpBoot;
10
11
use DI\FactoryInterface;
12
use PhpBoot\Console\ConsoleContainer;
13
use PhpBoot\Console\ConsoleContainerBuilder;
14
use PhpBoot\DI\Traits\EnableDIAnnotations;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class Console extends \Symfony\Component\Console\Application
20
{
21
    use EnableDIAnnotations;
22
23
    /**
24
     * @inject
25
     * @var ConsoleContainerBuilder
26
     */
27
    protected $consoleContainerBuilder;
28
29
    /**
30
     * @param FactoryInterface $factory
31
     * @return Console
32
     * @throws \DI\DependencyException
33
     * @throws \DI\NotFoundException
34
     */
35
    static public function create(FactoryInterface $factory)
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
36
    {
37
        return $factory->make(self::class);
38
    }
39
    /**
40
     * @param $className
41
     * @throws \Exception
42
     */
43 1
    public function loadCommandsFromClass($className)
44
    {
45 1
        $console = null;
0 ignored issues
show
Unused Code introduced by
$console is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
46 1
        $container = null;
0 ignored issues
show
Unused Code introduced by
$container is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
48 1
        $container = $this->consoleContainerBuilder->build($className);
49
        /**@var ConsoleContainer $container*/
50 1
        foreach ($container->getCommands() as $name => $command) {
51
            $command->setCode(function (InputInterface $input, OutputInterface $output)use ($container, $command){
52 1
                return $command->invoke($container, $input, $output);
53 1
            });
54 1
            $this->add($command);
55 1
        }
56 1
    }
57
58
    /**
59
     * @param $fromPath
60
     * @param string $namespace
61
     * @throws \Exception
62
     */
63 View Code Duplication
    public function loadRoutesFromPath($fromPath, $namespace = '')
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...
64
    {
65
        $dir = @dir($fromPath) or abort("dir $fromPath not exist");
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
66
67
        $getEach = function () use ($dir) {
68
            $name = $dir->read();
69
            if (!$name) {
70
                return $name;
71
            }
72
            return $name;
73
        };
74
75
        while (!!($entry = $getEach())) {
76
            if ($entry == '.' || $entry == '..') {
77
                continue;
78
            }
79
            $path = $fromPath . '/' . str_replace('\\', '/', $entry);
80
            if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) {
81
                $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4);
82
                $this->loadCommandsFromClass($class_name);
83
            } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
84
                //\Log::debug($path.' ignored');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
85
            }
86
        }
87
    }
88
89
}