Passed
Push — main ( 7f9db7...496340 )
by ikechukwu
20:55 queued 16:44
created

MakeActionCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 90
rs 10
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getOptions() 0 4 1
A alreadyExists() 0 4 2
A resolveStubPath() 0 5 2
A getDefaultNamespace() 0 3 1
A getStub() 0 3 1
1
<?php
2
3
namespace Ikechukwukalu\Makeservice\Console\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Symfony\Component\Console\Attribute\AsCommand;
7
use Symfony\Component\Console\Input\InputOption;
8
9
#[AsCommand(name: 'make:action')]
10
class MakeActionCommand extends GeneratorCommand
11
{
12
    /**
13
     * The console command name.
14
     *
15
     * @var string
16
     */
17
    protected $name = 'make:action';
18
19
    /**
20
     * The name of the console command.
21
     *
22
     * This name is used to identify the command during lazy loading.
23
     *
24
     * @var string|null
25
     *
26
     * @deprecated
27
     */
28
    protected static $defaultName = 'make:action';
29
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Create a new action class';
36
37
    /**
38
     * The type of class being generated.
39
     *
40
     * @var string
41
     */
42
    protected $type = 'Action';
43
44
    /**
45
     * Determine if the class already exists.
46
     *
47
     * @param  string  $rawName
48
     * @return bool
49
     */
50
    protected function alreadyExists($rawName)
51
    {
52
        return class_exists($rawName) ||
53
               $this->files->exists($this->getPath($this->qualifyClass($rawName)));
54
    }
55
56
    /**
57
     * Get the stub file for the generator.
58
     *
59
     * @return string
60
     */
61
    protected function getStub()
62
    {
63
        return __DIR__.'/stubs/action.stub';
64
    }
65
66
    /**
67
     * Resolve the fully-qualified path to the stub.
68
     *
69
     * @param  string  $stub
70
     * @return string
71
     */
72
    protected function resolveStubPath($stub)
73
    {
74
        return file_exists($customPath = $this->laravel->basePath(trim($stub, '/')))
75
                        ? $customPath
76
                        : __DIR__.$stub;
77
    }
78
79
    /**
80
     * Get the default namespace for the class.
81
     *
82
     * @param  string  $rootNamespace
83
     * @return string
84
     */
85
    protected function getDefaultNamespace($rootNamespace)
86
    {
87
        return $rootNamespace.'\Actions';
88
    }
89
90
    /**
91
     * Get the console command options.
92
     *
93
     * @return array
94
     */
95
    protected function getOptions()
96
    {
97
        return [
98
            ['force', 'f', InputOption::VALUE_NONE, 'Create the class even if the action already exists'],
99
        ];
100
    }
101
}
102