Completed
Push — master ( b4d64e...1bc42b )
by recca
02:02
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 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
     * Parse the class name and format according to the root namespace.
34
     *
35
     * @param string $name
36
     * @return string
37
     */
38
    protected function qualifyClass($name)
39
    {
40
        $rootNamespace = $this->rootNamespace();
41
42
        if (Str::startsWith($name, $rootNamespace)) {
43
            return $name;
44
        }
45
46
        $name = str_replace('/', '\\', $name);
47
48
        return $this->qualifyClass(
49
            $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name
50
        );
51
    }
52
53
    /**
54
     * Get the root namespace for the class.
55
     *
56
     * @return string
57
     */
58 4
    protected function rootNamespace()
59
    {
60 4
        return $this->laravel->getNamespace();
61
    }
62
63
    /**
64
     * getStubResource.
65
     *
66
     * @param string $path
0 ignored issues
show
Bug introduced by
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
67
     * @return string
68
     */
69 7
    protected function getStubResource($stub)
70
    {
71
        // return __DIR__.'/../../resources/stubs/'.$stub;
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
72
73 7
        $root = $this->laravel->basePath().'/resources/views/generator/';
74
75 7
        return $this->files->exists($root.$stub) === true
76 7
            ? $root.$stub
77 7
            : __DIR__.'/../../resources/stubs/'.$stub;
78
    }
79
}
80