Completed
Push — master ( a575ab...840688 )
by recca
04:51
created

GeneratorCommand::qualifyClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 6
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 6
    public function __construct(Filesystem $files, Generator $generator)
26
    {
27 6
        parent::__construct($files);
28 6
        $this->generator = $generator;
29 6
    }
30
31
    /**
32
     * Parse the class name and format according to the root namespace.
33
     *
34
     * @param string $name
35
     * @return string
36
     */
37
    protected function qualifyClass($name)
38
    {
39
        $rootNamespace = $this->rootNamespace();
40
41
        if (Str::startsWith($name, $rootNamespace)) {
42
            return $name;
43
        }
44
45
        $name = str_replace('/', '\\', $name);
46
47
        return $this->qualifyClass(
48
            $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name
49
        );
50
    }
51
52
    /**
53
     * Get the root namespace for the class.
54
     *
55
     * @return string
56
     */
57 3
    protected function rootNamespace()
58
    {
59 3
        return $this->laravel->getNamespace();
60
    }
61
}
62