Completed
Push — master ( 880a30...6b3c1e )
by Fumio
02:31
created

AddonCheckCommand::handle()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3.0213

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 21
ccs 13
cts 15
cp 0.8667
rs 9.3143
cc 3
eloc 12
nc 4
nop 0
crap 3.0213
1
<?php
2
3
namespace Jumilla\Addomnipot\Laravel\Console;
4
5
use Illuminate\Console\Command;
6
use Symfony\Component\Finder\Finder;
7
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment;
8
9
class AddonCheckCommand extends Command
10
{
11
    /**
12
     * The console command signature.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'addon:check';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Check addons';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30 1
    public function handle()
31
    {
32 1
        $files = $this->laravel['files'];
33 1
        $env = $this->laravel[AddonEnvironment::class];
34
35
        // make addons/
36 1
        $addonsDirectory = $env->path();
37 1
        if (!$files->exists($addonsDirectory)) {
38
            $files->makeDirectory($addonsDirectory);
39
        }
40
41 1
        $this->line('> Check Start.');
42 1
        $this->line('--------');
43
44 1
        $addons = $env->addons();
45 1
        foreach ($addons as $addon) {
46 1
            $this->dump($addon);
47 1
        }
48
49 1
        $this->line('> Check Finished!');
50 1
    }
51
52 1
    protected function dump($addon)
53
    {
54 1
        $this->dumpProperties($addon);
55 1
        $this->dumpClasses($addon);
56 1
        $this->dumpServiceProviders($addon);
57
58 1
        $this->line('--------');
59 1
    }
60
61 1
    protected function dumpProperties($addon)
62
    {
63 1
        $this->info(sprintf('Addon "%s"', $addon->name()));
64 1
        $this->info(sprintf('Path: %s', $addon->relativePath($this->laravel)));
65 1
        $this->info(sprintf('PHP namespace: %s', $addon->phpNamespace()));
66 1
    }
67
68 1
    protected function dumpClasses($addon)
69
    {
70
        // load laravel services
71 1
        $files = $this->laravel['files'];
0 ignored issues
show
Unused Code introduced by
$files 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...
72 1
        $env = $this->laravel[AddonEnvironment::class];
73
74
        // 全ディレクトリ下を探索する (PSR-4)
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
75 1
        foreach ($addon->config('addon.directories') as $directory) {
76 1
            $this->info(sprintf('PHP classes on "%s"', $directory));
77
78 1
            $classDirectoryPath = $addon->path($directory);
79
80 1
            if (!file_exists($classDirectoryPath)) {
81
                $this->line(sprintf('Warning: Class directory "%s" not found', $directory));
82
                continue;
83
            }
84
85
            // recursive find files
86 1
            $phpFilePaths = iterator_to_array((new Finder())->in($classDirectoryPath)->name('*.php')->files(), false);
87
88 1
            foreach ($phpFilePaths as $phpFilePath) {
89 1
                $relativePath = substr($phpFilePath, strlen($classDirectoryPath) + 1);
90
91 1
                $classFullName = $addon->phpNamespace().'\\'.$env->pathToClass($relativePath);
92
93 1
                $this->line(sprintf('  "%s" => %s', $relativePath, $classFullName));
94 1
            }
95 1
        }
96 1
    }
97
98 1
    protected function dumpServiceProviders($addon)
0 ignored issues
show
Unused Code introduced by
The parameter $addon is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99
    {
100 1
    }
101
}
102