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

ExtendPermissionCrudModel::getDefaultNamespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Backpack\PermissionManager\Console\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
7
class ExtendPermissionCrudModel extends GeneratorCommand
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'backpack:crud-permission-model';
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'backpack:crud-permission-model {name}';
22
23
    /**
24
     * The console command description.
25
     *
26
     * @var string
27
     */
28
    protected $description = 'Generate a Backpack CRUD Permission model';
29
30
    /**
31
     * The type of class being generated.
32
     *
33
     * @var string
34
     */
35
    protected $type = 'Model';
36
37
    /**
38
     * Get the stub file for the generator.
39
     *
40
     * @return string
41
     */
42
    protected function getStub()
43
    {
44
        return __DIR__.'/../stubs/crud-model-permission.stub';
45
    }
46
47
    /**
48
     * Get the destination class path.
49
     *
50
     * @param string $name
51
     *
52
     * @return string
53
     */
54 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...
55
    {
56
        // Get relative path name
57
        $name = str_replace_first($this->laravel->getNamespace(), '', $name);
58
        $name = str_replace('\\', '/', $name);
59
60
        // Pull expected filename from path
61
        $name_array = explode('/', $name);
62
        $file = array_pop($name_array);
63
        // Replace with Extended version
64
        $name_array[] = 'Extend'.$file;
65
66
        // Implode array to string
67
        $name = implode('/', $name_array);
68
69
        // Return new path
70
        return $this->laravel['path'].'/'.$name.'.php';
71
    }
72
73
    /**
74
     * Get the default namespace for the class.
75
     *
76
     * @param string $rootNamespace
77
     *
78
     * @return string
79
     */
80
    protected function getDefaultNamespace($rootNamespace)
81
    {
82
        return $rootNamespace.'\Models\Permissions';
83
    }
84
85
    /**
86
     * Replace the table name for the given stub.
87
     *
88
     * @param string $stub
89
     * @param string $name
90
     *
91
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be ExtendPermissionCrudModel?

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...
92
     */
93
    protected function replaceTable(&$stub, $name)
94
    {
95
        $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...
96
97
        $stub = str_replace('DummyTable', $table, $stub);
98
99
        return $this;
100
    }
101
102
    /**
103
     * Build the class with the given name.
104
     *
105
     * @param string $name
106
     *
107
     * @return string
108
     */
109
    protected function buildClass($name)
110
    {
111
        $stub = $this->files->get($this->getStub());
112
113
        return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name);
114
    }
115
116
    /**
117
     * Get the console command options.
118
     *
119
     * @return array
120
     */
121
    protected function getOptions()
122
    {
123
        return [
124
125
        ];
126
    }
127
}
128