Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( ec4e39...432da1 )
by Cristian
02:06
created

CrudControllerBackpackCommand::buildClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Backpack\Generators\Console\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Illuminate\Support\Str;
7
8
class CrudControllerBackpackCommand extends GeneratorCommand
9
{
10
    /**
11
     * The console command name.
12
     *
13
     * @var string
14
     */
15
    protected $name = 'backpack:crud-controller';
16
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'backpack:crud-controller {name}';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Generate a Backpack CRUD controller';
30
31
    /**
32
     * The type of class being generated.
33
     *
34
     * @var string
35
     */
36
    protected $type = 'Controller';
37
38
39
    /**
40
     * Get the destination class path.
41
     *
42
     * @param  string  $name
43
     * @return string
44
     */
45
    protected function getPath($name)
46
    {
47
        $name = str_replace($this->laravel->getNamespace(), '', $name);
0 ignored issues
show
Bug introduced by
The method getNamespace() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
49
        return $this->laravel['path'].'/'.str_replace('\\', '/', $name).'CrudController.php';
50
    }
51
52
    /**
53
     * Get the stub file for the generator.
54
     *
55
     * @return string
56
     */
57
    protected function getStub()
58
    {
59
        return __DIR__.'/../stubs/crud-controller.stub';
60
    }
61
62
    /**
63
     * Get the default namespace for the class.
64
     *
65
     * @param string $rootNamespace
66
     *
67
     * @return string
68
     */
69
    protected function getDefaultNamespace($rootNamespace)
70
    {
71
        return $rootNamespace.'\Http\Controllers\Admin';
72
    }
73
74
    /**
75
     * Replace the table name for the given stub.
76
     *
77
     * @param string $stub
78
     * @param string $name
79
     *
80
     * @return string
81
     */
82
    protected function replaceNameStrings(&$stub, $name)
83
    {
84
        $table = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_').'s';
85
86
        $stub = str_replace('DummyTable', $table, $stub);
87
        $stub = str_replace('dummy_class', strtolower(str_replace($this->getNamespace($name).'\\', '', $name)), $stub);
88
89
        return $this;
90
    }
91
92
    /**
93
     * Build the class with the given name.
94
     *
95
     * @param string $name
96
     *
97
     * @return string
98
     */
99
    protected function buildClass($name)
100
    {
101
        $stub = $this->files->get($this->getStub());
102
103
        return $this->replaceNamespace($stub, $name)->replaceNameStrings($stub, $name)->replaceClass($stub, $name);
104
    }
105
106
    /**
107
     * Get the console command options.
108
     *
109
     * @return array
110
     */
111
    protected function getOptions()
112
    {
113
        return [
114
115
        ];
116
    }
117
}
118