Passed
Push — master ( cd2210...3cb518 )
by Thomas
39s
created

MakeBackpackCrudController::getStub()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Webfactor\Laravel\Generators\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
7
class MakeBackpackCrudController extends GeneratorCommand
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'make:crud-controller';
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'make:crud-controller {name}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Generate a Backpack CRUD controller';
29
30
    /**
31
     * The type of class being generated.
32
     *
33
     * @var string
34
     */
35
    protected $type = 'Controller';
36
37
    /**
38
     * Get the destination class path.
39
     *
40
     * @param string $name
41
     *
42
     * @return string
43
     */
44
    protected function getPath($name)
45
    {
46
        $name = str_replace($this->laravel->getNamespace(), '', $name);
47
48
        return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'CrudController.php';
49
    }
50
51
    /**
52
     * Get the stub file for the generator.
53
     *
54
     * @return string
55
     */
56
    protected function getStub()
57
    {
58
        return __DIR__.'/../../stubs/crud-controller.stub';
59
    }
60
61
    /**
62
     * Get the default namespace for the class.
63
     *
64
     * @param string $rootNamespace
65
     *
66
     * @return string
67
     */
68
    protected function getDefaultNamespace($rootNamespace)
69
    {
70
        return $rootNamespace.'\Http\Controllers\Admin';
71
    }
72
73
    /**
74
     * Replace the table name for the given stub.
75
     *
76
     * @param string $stub
77
     * @param string $name
78
     *
79
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be MakeBackpackCrudController?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
80
     */
81
    protected function replaceNameStrings(&$stub, $name)
82
    {
83
        $table = str_plural(ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_'));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
84
85
        $stub = str_replace('DummyTable', $table, $stub);
86
        $stub = str_replace('dummy_class', strtolower(str_replace($this->getNamespace($name).'\\', '', $name)), $stub);
87
88
        return $this;
89
    }
90
91
    /**
92
     * Build the class with the given name.
93
     *
94
     * @param string $name
95
     *
96
     * @return string
97
     */
98
    protected function buildClass($name)
99
    {
100
        $stub = $this->files->get($this->getStub());
101
102
        return $this->replaceNamespace($stub, $name)->replaceNameStrings($stub, $name)->replaceClass($stub, $name);
103
    }
104
105
    /**
106
     * Get the console command options.
107
     *
108
     * @return array
109
     */
110
    protected function getOptions()
111
    {
112
        return [
113
114
        ];
115
    }
116
}
117