Tool   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 26 2
1
<?php
2
3
namespace Yaro\Jarboe\Console\Commands\Make;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\File;
7
use Illuminate\Support\Str;
8
use Yaro\Jarboe\Table\Toolbar\Interfaces\ToolInterface;
9
10
class Tool extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'jarboe:make:tool {class}';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Make tool for toolbar.';
25
26
    /**
27
     * Execute the console command.
28
     *
29
     * @return mixed
30
     */
31
    public function handle()
32
    {
33
        $className = (string) $this->argument('class');
34
35
        $packagePath = __DIR__ .'/../../../../';
36
        $stub = file_get_contents($packagePath .'stubs/tool.stub');
37
38
        $position = $this->choice('Tool position?', [
39
            ToolInterface::POSITION_HEADER,
40
            ToolInterface::POSITION_BODY_TOP,
41
            ToolInterface::POSITION_BODY_BOTTOM,
42
            ToolInterface::POSITION_BODY_BOTH,
43
        ]);
44
        $position = strtoupper('position_'. $position);
45
        $ident = Str::random();
46
        $view = Str::snake($className);
47
48
        $tool = sprintf($stub, $className, $position, $ident, $view);
49
        $filepath = app_path(sprintf('Jarboe/Toolbar/%s.php', $className));
50
51
        if (!File::exists(app_path('Jarboe/Toolbar'))) {
52
            File::makeDirectory(app_path('Jarboe/Toolbar'), 0775, true, false);
53
        }
54
        File::put($filepath, $tool);
55
56
        $this->info('Created: '. $filepath);
57
    }
58
}
59