Completed
Push — master ( 402287...b4d64e )
by recca
02:03
created

GeneratorCommand::qualifyClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
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 6
    protected function qualifyClass($name)
38
    {
39 6
        $rootNamespace = $this->rootNamespace();
40
41 6
        if (Str::startsWith($name, $rootNamespace)) {
42 6
            return $name;
43
        }
44
45 6
        $name = str_replace('/', '\\', $name);
46
47 6
        return $this->qualifyClass(
48 6
            $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name
49 6
        );
50
    }
51
52
    /**
53
     * Get the root namespace for the class.
54
     *
55
     * @return string
56
     */
57 6
    protected function rootNamespace()
58
    {
59 6
        return $this->laravel->getNamespace();
60
    }
61
}
62