PanelMakeCommand   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 3 Features 0
Metric Value
eloc 31
c 5
b 3
f 0
dl 0
loc 126
ccs 0
cts 31
cp 0
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A templatePath() 0 5 1
A getStub() 0 7 2
A getDefaultNamespace() 0 3 1
A getOptions() 0 4 1
A replaceClass() 0 8 1
A getViewName() 0 3 1
A handle() 0 14 2
A templateContents() 0 9 1
1
<?php
2
3
namespace Terranet\Administrator\Console;
4
5
use Illuminate\Console\GeneratorCommand;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\GeneratorCommand was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Support\Str;
7
use Symfony\Component\Console\Input\InputOption;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Console\Input\InputOption was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class PanelMakeCommand extends GeneratorCommand
10
{
11
    /**
12
     * The console command name.
13
     *
14
     * @var string
15
     */
16
    protected $name = 'administrator:panel';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Create new administrator dashboard panel.';
24
25
    /**
26
     * The type of class being generated.
27
     *
28
     * @var string
29
     */
30
    protected $type = 'Dashboard';
31
32
    public function handle()
33
    {
34
        parent::handle();
35
36
        if (!$this->option('no-view')) {
37
            $name = class_basename($this->qualifyClass($this->getNameInput()));
38
39
            $view = $this->templatePath($this->getViewName());
40
41
            $this->makeDirectory($view);
42
43
            $this->files->put($view, $this->templateContents(
44
                $name,
45
                ltrim(str_replace(base_path(), '', $view), \DIRECTORY_SEPARATOR)
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
                ltrim(str_replace(/** @scrutinizer ignore-call */ base_path(), '', $view), \DIRECTORY_SEPARATOR)
Loading history...
46
            ));
47
        }
48
    }
49
50
    /**
51
     * Replace the class name for the given stub.
52
     *
53
     * @param string $stub
54
     * @param string $name
55
     *
56
     * @return string
57
     */
58
    protected function replaceClass($stub, $name)
59
    {
60
        $class = str_replace($this->getNamespace($name).'\\', '', $name);
61
        $view = $this->getViewName();
62
63
        $stub = str_replace('DummyClass', $class, $stub);
64
65
        return str_replace('DummyTemplate', 'admin.dashboard.'.$view, $stub);
66
    }
67
68
    /**
69
     * Get the stub file for the generator.
70
     *
71
     * @return string
72
     */
73
    protected function getStub()
74
    {
75
        if ($this->option('no-view')) {
76
            return __DIR__.'/stubs/dashboard.panel.simple.stub';
77
        }
78
79
        return __DIR__.'/stubs/dashboard.panel.stub';
80
    }
81
82
    /**
83
     * Get the default namespace for the class.
84
     *
85
     * @param string $rootNamespace
86
     *
87
     * @return string
88
     */
89
    protected function getDefaultNamespace($rootNamespace)
90
    {
91
        return $rootNamespace.'\\'.config('administrator.paths.panel');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
        return $rootNamespace.'\\'./** @scrutinizer ignore-call */ config('administrator.paths.panel');
Loading history...
92
    }
93
94
    /**
95
     * Get the console command options.
96
     *
97
     * @return array
98
     */
99
    protected function getOptions()
100
    {
101
        return [
102
            ['no-view', null, InputOption::VALUE_NONE, 'Do not generate view template for this panel.'],
103
        ];
104
    }
105
106
    /**
107
     * @param $name
108
     *
109
     * @return string
110
     */
111
    protected function templatePath($name)
112
    {
113
        $tpl = base_path('resources/views/admin/dashboard/'.$name.'.blade.php');
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

113
        $tpl = /** @scrutinizer ignore-call */ base_path('resources/views/admin/dashboard/'.$name.'.blade.php');
Loading history...
114
115
        return $tpl;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    protected function getViewName()
122
    {
123
        return Str::snake(class_basename($this->qualifyClass($this->getNameInput())));
124
    }
125
126
    private function templateContents($title, $path)
127
    {
128
        return <<<OUT
129
<div class="panel">
130
    <div class="panel-heading">
131
        <h4 class="panel-title">{$title}</h4>
132
    </div>
133
    <div class="panel-body">
134
        <p class="well">Check me out here [{$path}]</p>
135
    </div>
136
</div>
137
OUT;
138
    }
139
}
140