GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CrudControllerMakeCommand::getDefaultNamespace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Akibatech\Crud\Console;
4
5
use Illuminate\Console\GeneratorCommand;
6
use Illuminate\Support\Str;
7
use Symfony\Component\Console\Input\InputArgument;
8
9
class CrudControllerMakeCommand extends GeneratorCommand
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name = 'make:crud:controller';
15
16
    /**
17
     * @var string
18
     */
19
    protected $description = 'Create a new crud friendly controller class';
20
21
    /**
22
     * @var string
23
     */
24
    protected $type = 'Controller';
25
26
    /**
27
     * @return  string
28
     */
29
    protected function getStub()
30
    {
31
        return __DIR__ . '/stubs/controller.stub';
32
    }
33
34
    /**
35
     * @param   string  $rootNamespace
36
     * @return  string
37
     */
38
    protected function getDefaultNamespace($rootNamespace)
39
    {
40
        return $rootNamespace . '\Http\Controllers';
41
    }
42
43
    /**
44
     * Get and parse the model name.
45
     *
46
     * @param   void
47
     * @return  string
48
     */
49
    protected function getModelName()
50
    {
51
        $name = trim($this->argument('model'));
52
        $rootNamespace = $this->laravel->getNamespace();
53
54
        if (Str::contains($name, '/'))
55
        {
56
            $name = str_replace('/', '\\', $name);
57
        }
58
59
        if (Str::startsWith($name, $rootNamespace))
60
        {
61
            return '\\' . $name;
62
        }
63
64
        return '\\' . $rootNamespace . $name;
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    protected function getArguments()
71
    {
72
        return array_merge(parent::getArguments(), [
73
            ['model', InputArgument::REQUIRED, 'The name of the model, for example, "Post" or "App/Post"'],
74
        ]);
75
    }
76
77
    /**
78
     * @param   string  $name
79
     * @return  string
80
     */
81
    protected function buildClass($name)
82
    {
83
        $namespace = $this->getNamespace($name);
84
85
        $modelName = $this->getModelName();
86
        $modelClass = $modelName . '::class';
87
88
        $class = parent::buildClass($name);
89
        $class = str_replace("use {$namespace}\Controller;\n", '', $class);
90
        $class = str_replace('DummyModelClass', $modelClass, $class);
91
        $class = str_replace('DummyModel', $modelName, $class);
92
93
        return $class;
94
    }
95
}
96