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']; |
|
|
|
|
72
|
1 |
|
$env = $this->laravel[AddonEnvironment::class]; |
73
|
|
|
|
74
|
|
|
// 全ディレクトリ下を探索する (PSR-4) |
|
|
|
|
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) |
|
|
|
|
99
|
|
|
{ |
100
|
1 |
|
} |
101
|
|
|
} |
102
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.