Completed
Push — master ( f9d404...9615a2 )
by recca
01:36
created

GeneratorCommand::fire()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Recca0120\Generator\Console;
4
5
use Illuminate\Support\Str;
6
use Recca0120\Generator\Generator;
7
use Illuminate\Filesystem\Filesystem;
8
use Illuminate\Console\GeneratorCommand as BaseCommand;
9
10
abstract class GeneratorCommand extends BaseCommand
11
{
12
    /**
13
     * $generator.
14
     *
15
     * @var \Recca0120\Generator\Generator
16
     */
17
    protected $generator;
18
19
    /**
20
     * Create a new controller creator command instance.
21
     *
22
     * @param \Illuminate\Filesystem\Filesystem $files
23
     * @param \Recca0120\Generator\Generator
24
     */
25 7
    public function __construct(Filesystem $files, Generator $generator)
26
    {
27 7
        parent::__construct($files);
28
29 7
        $this->generator = $generator;
30 7
    }
31
32
    /**
33
     * fire.
34
     *
35
     * @return void
36
     */
37 7
    public function fire()
38
    {
39 7
        $this->handle();
40 7
    }
41
42
    /**
43
     * Parse the class name and format according to the root namespace.
44
     *
45
     * @param string $name
46
     * @return string
47
     */
48 7
    protected function qualifyClass($name)
49
    {
50 7
        $rootNamespace = $this->rootNamespace();
51
52 7
        if (Str::startsWith($name, $rootNamespace)) {
53 7
            return $name;
54
        }
55
56 7
        $name = str_replace('/', '\\', $name);
57
58 7
        return $this->qualifyClass(
59 7
            $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name
60
        );
61
    }
62
63
    /**
64
     * Get the root namespace for the class.
65
     *
66
     * @return string
67
     */
68 7
    protected function rootNamespace()
69
    {
70 7
        return $this->laravel->getNamespace();
71
    }
72
73
    /**
74
     * getStubResource.
75
     *
76
     * @param string $stub
77
     * @param string $folder
78
     * @return string
79
     */
80 7
    protected function getStubResource($stub, $folder = 'app')
81
    {
82 7
        $root = $this->laravel->basePath().'/resources/views/generator/'.$folder.'/';
83
84 7
        return $this->files->exists($root.$stub) === true
85
            ? $root.$stub
86 7
            : __DIR__.'/../../resources/stubs/'.$folder.'/'.$stub;
87
    }
88
}
89