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.

Console::loadCommandsFromClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 14
ccs 10
cts 10
cp 1
crap 2
rs 9.7998
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 DI\InvokerInterface;
13
use PhpBoot\Console\ConsoleContainer;
14
use PhpBoot\Console\ConsoleContainerBuilder;
15
use PhpBoot\DI\Traits\EnableDIAnnotations;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
class Console extends \Symfony\Component\Console\Application
21
{
22
    use EnableDIAnnotations;
23
24
    /**
25
     * @inject
26
     * @var ConsoleContainerBuilder
27
     */
28
    protected $consoleContainerBuilder;
29
30
    /**
31
     * @inject
32
     * @var InvokerInterface
33
     */
34
    private $diInvoker;
35
36
    /**
37
     * @param FactoryInterface $factory
38
     * @return Console
39
     * @throws \DI\DependencyException
40
     * @throws \DI\NotFoundException
41
     */
42
    static public function create(FactoryInterface $factory)
43
    {
44
        return $factory->make(self::class);
45
    }
46
    /**
47
     * @param $className
48
     * @throws \Exception
49
     */
50 1
    public function loadCommandsFromClass($className)
51
    {
52 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...
53 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...
54
55 1
        $container = $this->consoleContainerBuilder->build($className);
56
        /**@var ConsoleContainer $container*/
57 1
        foreach ($container->getCommands() as $name => $command) {
58
            $command->setCode(function (InputInterface $input, OutputInterface $output)use ($container, $command){
59 1
                return $this->diInvoker->call([$command, 'invoke'], ['container'=>$container, 'input'=>$input, 'output'=>$output]);
60 1
            });
61 1
            $this->add($command);
62 1
        }
63 1
    }
64
65
    /**
66
     * @param $fromPath
67
     * @param string $namespace
68
     * @throws \Exception
69
     */
70 View Code Duplication
    public function loadCommandsFromPath($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...
71
    {
72
        $dir = @dir($fromPath) or abort("dir $fromPath not exist");
73
74
        $getEach = function () use ($dir) {
75
            $name = $dir->read();
76
            if (!$name) {
77
                return $name;
78
            }
79
            return $name;
80
        };
81
82
        while (!!($entry = $getEach())) {
83
            if ($entry == '.' || $entry == '..') {
84
                continue;
85
            }
86
            $path = $fromPath . '/' . str_replace('\\', '/', $entry);
87
            if (is_file($path) && substr_compare($entry, '.php', strlen($entry) - 4, 4, true) == 0) {
88
                $class_name = $namespace . '\\' . substr($entry, 0, strlen($entry) - 4);
89
                $this->loadCommandsFromClass($class_name);
90
            } else {
91
                //\Log::debug($path.' ignored');
92
            }
93
        }
94
    }
95
96
}