Passed
Push — main ( fae6b8...4597d7 )
by ikechukwu
12:05
created

MakeEnumCommand::getDefaultNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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