Completed
Push — master ( ec3c57...7e8511 )
by recca
02:01
created

GeneratorCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 52
ccs 6
cts 14
cp 0.4286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A rootNamespace() 0 4 1
A qualifyClass() 0 14 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
    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