1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jumilla\Addomnipot\Laravel\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Symfony\Component\Finder\Finder; |
7
|
|
|
use Illuminate\Filesystem\Filesystem; |
8
|
|
|
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment; |
9
|
|
|
use UnexpectedValueException; |
10
|
|
|
|
11
|
|
|
class AddonStatusCommand extends Command |
12
|
|
|
{ |
13
|
|
|
use Functions; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The console command signature. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'addon:status |
21
|
|
|
{addon? : Name of addon.} |
22
|
|
|
'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Addons status'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Execute the console command. |
33
|
|
|
* |
34
|
|
|
* @return mixed |
35
|
|
|
*/ |
36
|
2 |
|
public function handle(Filesystem $filesystem, AddonEnvironment $env) |
37
|
|
|
{ |
38
|
|
|
// make addons/ |
39
|
2 |
|
$addons_directory = $env->path(); |
40
|
2 |
|
if (!$filesystem->exists($addons_directory)) { |
41
|
|
|
$filesystem->makeDirectory($addons_directory); |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
$addon_name = $this->argument('addon'); |
45
|
2 |
|
if (! $addon_name) { |
46
|
1 |
|
$addons = $env->addons(); |
47
|
|
|
|
48
|
1 |
|
$this->line('--------'); |
49
|
1 |
|
foreach ($addons as $addon) { |
50
|
1 |
|
$this->dump($addon); |
51
|
1 |
|
$this->line('--------'); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
else { |
55
|
1 |
|
$addon = $env->addon($addon_name); |
56
|
|
|
|
57
|
|
|
// check addon |
58
|
1 |
|
if ($addon === null) { |
59
|
|
|
throw new UnexpectedValueException(sprintf('Addon "%s" is not found.', $addon_name)); |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
$this->dump($addon); |
63
|
|
|
} |
64
|
2 |
|
} |
65
|
|
|
|
66
|
2 |
|
protected function dump($addon) |
67
|
|
|
{ |
68
|
2 |
|
$this->dumpProperties($addon); |
69
|
2 |
|
$this->dumpClasses($addon); |
70
|
2 |
|
$this->dumpServiceProviders($addon); |
71
|
2 |
|
} |
72
|
|
|
|
73
|
2 |
|
protected function dumpProperties($addon) |
74
|
|
|
{ |
75
|
2 |
|
$this->info(sprintf('Addon "%s"', $addon->name())); |
76
|
2 |
|
$this->info(sprintf('Path: %s', $addon->relativePath($this->laravel))); |
77
|
2 |
|
$this->info(sprintf('PHP namespace: %s', $addon->phpNamespace())); |
78
|
2 |
|
} |
79
|
|
|
|
80
|
2 |
|
protected function dumpClasses($addon) |
81
|
|
|
{ |
82
|
|
|
// load laravel services |
83
|
2 |
|
$files = $this->laravel['files']; |
|
|
|
|
84
|
2 |
|
$env = $this->laravel[AddonEnvironment::class]; |
85
|
|
|
|
86
|
|
|
// 全ディレクトリ下を探索する (PSR-4) |
|
|
|
|
87
|
2 |
|
foreach ($addon->config('addon.directories', []) as $directory) { |
88
|
|
|
$this->info(sprintf('PHP classes on "%s"', $directory)); |
89
|
|
|
|
90
|
|
|
$classDirectoryPath = $addon->path($directory); |
91
|
|
|
|
92
|
|
|
if (!file_exists($classDirectoryPath)) { |
93
|
|
|
$this->line(sprintf('Warning: Class directory "%s" not found', $directory)); |
94
|
|
|
continue; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// recursive find files |
98
|
|
|
$phpFilePaths = iterator_to_array((new Finder())->in($classDirectoryPath)->name('*.php')->files(), false); |
99
|
|
|
|
100
|
|
|
foreach ($phpFilePaths as $phpFilePath) { |
101
|
|
|
$relativePath = substr($phpFilePath, strlen($classDirectoryPath) + 1); |
102
|
|
|
|
103
|
|
|
$classFullName = $addon->phpNamespace().'\\'.$env->pathToClass($relativePath); |
104
|
|
|
|
105
|
|
|
$this->line(sprintf(' "%s" => %s', $relativePath, $classFullName)); |
106
|
|
|
} |
107
|
|
|
} |
108
|
2 |
|
} |
109
|
|
|
|
110
|
2 |
|
protected function dumpServiceProviders($addon) |
|
|
|
|
111
|
|
|
{ |
112
|
2 |
|
} |
113
|
|
|
} |
114
|
|
|
|
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.