Completed
Push — master ( 284085...99e334 )
by Fumio
02:01
created

AddonListCommand::handle()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.0072

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 8
nop 2
dl 0
loc 23
ccs 12
cts 13
cp 0.9231
crap 4.0072
rs 8.7972
c 0
b 0
f 0
1
<?php
2
3
namespace Jumilla\Addomnipot\Laravel\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Filesystem\Filesystem;
7
use Jumilla\Addomnipot\Laravel\Environment as AddonEnvironment;
8
9
class AddonListCommand extends Command
10
{
11
    use Functions;
12
13
    /**
14
     * The console command signature.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'addon:list';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'List up addon information';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return mixed
31
     */
32 1
    public function handle(Filesystem $filesystem, AddonEnvironment $env)
33
    {
34
        // make addons/
35 1
        $addonsDirectory = $env->path();
36 1
        if (!$filesystem->exists($addonsDirectory)) {
37
            $filesystem->makeDirectory($addonsDirectory);
38
        }
39
40
        // copy app/config/addon.php
41 1
        $addonConfigSourceFile = __DIR__.'/../../config/addon.php';
42 1
        $addonConfigFile = $this->laravel['path.config'].'/addon.php';
43 1
        if (!$filesystem->exists($addonConfigFile)) {
44 1
            $filesystem->copy($addonConfigSourceFile, $addonConfigFile);
45
46 1
            $this->info('make config: '.$addonConfigFile);
47
        }
48
49
        // show lists
50 1
        $addons = $env->addons();
51 1
        foreach ($addons as $addon) {
52 1
            $this->dump($addon);
53
        }
54 1
    }
55
56 1
    protected function dump($addon)
57
    {
58 1
        $path = $addon->relativePath($this->laravel);
59
60 1
        $this->line("<info>{$addon->name()}</info> {$path}");
61 1
    }
62
}
63