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
Pull Request — master (#24)
by
unknown
02:02
created

ExtendPermissionCrudController::getPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 18
loc 18
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace Backpack\PermissionManager\Console\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
7
class ExtendPermissionCrudController extends GeneratorCommand
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'backpack:crud-permission-controller';
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'backpack:crud-permission-controller {name} {--user}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Generate a Backpack CRUD Permission 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 View Code Duplication
    protected function getPath($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        // Get relative path name
47
        $name = str_replace_first($this->laravel->getNamespace(), '', $name);
48
        $name = str_replace('\\', '/', $name);
49
50
        // Pull expected filename from path
51
        $name_array = explode('/', $name);
52
        $file = array_pop($name_array);
53
        // Replace with Extended version
54
        $name_array[] = 'Extend'.$file;
55
56
        // Implode array to string
57
        $name = implode('/', $name_array);
58
59
        // Return new path
60
        return $this->laravel['path'].'/'.$name.'CrudController.php';
61
    }
62
63
    /**
64
     * Get the stub file for the generator.
65
     *
66
     * @return string
67
     */
68
    protected function getStub()
69
    {
70
        if ($this->option('user')) {
71
            return __DIR__.'/../stubs/crud-controller-user.stub';
72
        }
73
        return __DIR__.'/../stubs/crud-contoller-permission.stub';
74
    }
75
76
    /**
77
     * Get the default namespace for the class.
78
     *
79
     * @param string $rootNamespace
80
     *
81
     * @return string
82
     */
83
    protected function getDefaultNamespace($rootNamespace)
84
    {
85
        return $rootNamespace.'\Http\Controllers\Permissions';
86
    }
87
88
    /**
89
     * Replace the table name for the given stub.
90
     *
91
     * @param string $stub
92
     * @param string $name
93
     *
94
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be ExtendPermissionCrudController?

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...
95
     */
96
    protected function replaceNameStrings(&$stub, $name)
97
    {
98
        $table = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_').'s';
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 133 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...
99
100
        $stub = str_replace('DummyTable', $table, $stub);
101
        $stub = str_replace('dummy_class', strtolower(str_replace($this->getNamespace($name).'\\', '', $name)), $stub);
102
103
        return $this;
104
    }
105
106
    /**
107
     * Build the class with the given name.
108
     *
109
     * @param string $name
110
     *
111
     * @return string
112
     */
113
    protected function buildClass($name)
114
    {
115
        $stub = $this->files->get($this->getStub());
116
117
        return $this->replaceNamespace($stub, $name)->replaceNameStrings($stub, $name)->replaceClass($stub, 'Extend'.$name);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 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...
118
    }
119
120
    /**
121
     * Get the console command options.
122
     *
123
     * @return array
124
     */
125
    protected function getOptions()
126
    {
127
        return [
128
129
        ];
130
    }
131
}
132