Completed
Push — master ( a19a47...15bbc5 )
by Arjay
15:59
created

WidgetPublishCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 14 2
1
<?php
2
3
namespace Yajra\CMS\Console;
4
5
use Illuminate\Console\Command;
6
use Yajra\CMS\Repositories\Extension\Repository;
7
8
class WidgetPublishCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'widget:install {name} {--path}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'Install YajraCMS widget extension.';
23
24
    /**
25
     * @var \Yajra\CMS\Repositories\Extension\Repository
26
     */
27
    private $extensions;
28
29
    /**
30
     * Create a new command instance.
31
     *
32
     * @param \Yajra\CMS\Repositories\Extension\Repository $extensions
33
     */
34
    public function __construct(Repository $extensions)
35
    {
36
        parent::__construct();
37
        $this->extensions = $extensions;
38
    }
39
40
    /**
41
     * Execute the console command.
42
     *
43
     * @return mixed
44
     */
45
    public function handle()
46
    {
47
        $path = app_path('Widgets') . DIRECTORY_SEPARATOR . $this->argument('name') . '.json';
48
49
        if ($this->option('path')) {
50
            $path = base_path($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, base_path() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
51
        }
52
53
        $this->extensions->registerManifest($path);
54
        $this->laravel->make('cache.store')->forget('extensions.widgets');
55
        $this->laravel->make('cache.store')->forget('extensions.all');
56
57
        $this->info($this->argument('name') . ' widget extension installed!');
58
    }
59
}
60