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 (#14)
by Owen
02:17
created

CrudModelBackpackCommand::buildMigration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Backpack\Generators\Console\Commands;
4
5
use Illuminate\Console\GeneratorCommand;
6
7
class CrudModelBackpackCommand extends GeneratorCommand
8
{
9
    /**
10
     * The console command name.
11
     *
12
     * @var string
13
     */
14
    protected $name = 'backpack:crud-model';
15
16
    /**
17
     * The name and signature of the console command.
18
     *
19
     * @var string
20
     */
21
    protected $signature = 'backpack:crud-model
22
                            {name : Name of the model}
23
                            {--nomigration : Disables creating of the migration file}';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Generate a Backpack CRUD model and migration';
31
32
    /**
33
     * The type of class being generated.
34
     *
35
     * @var string
36
     */
37
    protected $type = 'Model';
38
39
    /**
40
     * Get the stub file for the generator.
41
     *
42
     * @return string
43
     */
44
    protected function getStub()
45
    {
46
        return __DIR__.'/../stubs/crud-model.stub';
47
    }
48
49
    /**
50
     * Get the default namespace for the class.
51
     *
52
     * @param string $rootNamespace
53
     *
54
     * @return string
55
     */
56
    protected function getDefaultNamespace($rootNamespace)
57
    {
58
        return $rootNamespace.'\Models';
59
    }
60
61
    /**
62
     * Replace the table name for the given stub.
63
     *
64
     * @param string $stub
65
     * @param string $name
66
     *
67
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be CrudModelBackpackCommand?

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...
68
     */
69
    protected function replaceTable(&$stub, $name)
70
    {
71
        $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...
72
73
        $stub = str_replace('DummyTable', $table, $stub);
74
75
        return $this;
76
    }
77
78
    /**
79
     * Build the class with the given name.
80
     *
81
     * @param string $name
82
     *
83
     * @return string
84
     */
85
    protected function buildClass($name)
86
    {
87
        $stub = $this->files->get($this->getStub());
88
89
        return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name);
90
    }
91
92
    /**
93
     * Get the console command options.
94
     *
95
     * @return array
96
     */
97
    protected function getOptions()
98
    {
99
        return [
100
101
        ];
102
    }
103
104
    protected function buildMigration($name)
105
    {
106
        \Artisan::call('make:migration', [
107
            'name' => 'create_'.snake_case($name).'_table',
108
            '--create' => camel_case($name),
109
        ]);
110
    }
111
112
    public function handle()
113
    {
114
        $name = $this->argument('name');
115
116
        if (! $this->option('nomigration')) {
117
            $this->buildMigration($name);
118
        }
119
    }
120
}
121