Completed
Push — develop ( df9395...08456a )
by Abdelrahman
16:28
created

ConfigMakeCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStub() 0 4 1
A getPath() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\Console\Commands;
6
7
use Illuminate\Console\GeneratorCommand;
8
use Cortex\Foundation\Traits\ConsoleMakeModuleCommand;
9
10
class ConfigMakeCommand extends GeneratorCommand
11
{
12
    use ConsoleMakeModuleCommand;
13
14
    /**
15
     * The console command name.
16
     *
17
     * @var string
18
     */
19
    protected $name = 'make:config';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a new config file';
27
28
    /**
29
     * The type of class being generated.
30
     *
31
     * @var string
32
     */
33
    protected $type = 'Config';
34
35
    /**
36
     * Get the stub file for the generator.
37
     *
38
     * @return string
39
     */
40
    protected function getStub()
41
    {
42
        return __DIR__.'/../../../resources/stubs/config.stub';
43
    }
44
45
    /**
46
     * Get the destination class path.
47
     *
48
     * @param  string $name
49
     *
50
     * @throws \Exception
51
     *
52
     * @return string
53
     */
54
    protected function getPath($name)
55
    {
56
        $name = str_replace_first($this->rootNamespace(), $this->moduleName().DIRECTORY_SEPARATOR.'config', $name);
57
58
        if (! $this->files->exists($path = $this->laravel['path'].DIRECTORY_SEPARATOR.$this->moduleName())) {
59
            throw new \Exception("Invalid path: {$path}");
60
        }
61
62
        return $this->laravel['path'].DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $name).'.php';
63
    }
64
}
65