We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
@@ 7-101 (lines=95) @@ | ||
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 {name}'; |
|
22 | ||
23 | /** |
|
24 | * The console command description. |
|
25 | * |
|
26 | * @var string |
|
27 | */ |
|
28 | protected $description = 'Generate a Backpack CRUD 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.stub'; |
|
45 | } |
|
46 | ||
47 | /** |
|
48 | * Get the default namespace for the class. |
|
49 | * |
|
50 | * @param string $rootNamespace |
|
51 | * |
|
52 | * @return string |
|
53 | */ |
|
54 | protected function getDefaultNamespace($rootNamespace) |
|
55 | { |
|
56 | return $rootNamespace.'\Models'; |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * Replace the table name for the given stub. |
|
61 | * |
|
62 | * @param string $stub |
|
63 | * @param string $name |
|
64 | * |
|
65 | * @return string |
|
66 | */ |
|
67 | protected function replaceTable(&$stub, $name) |
|
68 | { |
|
69 | $table = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_').'s'; |
|
70 | ||
71 | $stub = str_replace('DummyTable', $table, $stub); |
|
72 | ||
73 | return $this; |
|
74 | } |
|
75 | ||
76 | /** |
|
77 | * Build the class with the given name. |
|
78 | * |
|
79 | * @param string $name |
|
80 | * |
|
81 | * @return string |
|
82 | */ |
|
83 | protected function buildClass($name) |
|
84 | { |
|
85 | $stub = $this->files->get($this->getStub()); |
|
86 | ||
87 | return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name); |
|
88 | } |
|
89 | ||
90 | /** |
|
91 | * Get the console command options. |
|
92 | * |
|
93 | * @return array |
|
94 | */ |
|
95 | protected function getOptions() |
|
96 | { |
|
97 | return [ |
|
98 | ||
99 | ]; |
|
100 | } |
|
101 | } |
|
102 |
@@ 7-105 (lines=99) @@ | ||
4 | ||
5 | use Illuminate\Console\GeneratorCommand; |
|
6 | ||
7 | class ModelBackpackCommand extends GeneratorCommand |
|
8 | { |
|
9 | /** |
|
10 | * The console command name. |
|
11 | * |
|
12 | * @var string |
|
13 | */ |
|
14 | protected $name = 'backpack:model'; |
|
15 | ||
16 | /** |
|
17 | * The name and signature of the console command. |
|
18 | * |
|
19 | * @var string |
|
20 | */ |
|
21 | protected $signature = 'backpack:model {name} {--softdelete}'; |
|
22 | ||
23 | /** |
|
24 | * The console command description. |
|
25 | * |
|
26 | * @var string |
|
27 | */ |
|
28 | protected $description = 'Generate a backpack templated 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 | if ($this->option('softdelete')) { |
|
45 | return __DIR__.'/../stubs/model-softdelete.stub'; |
|
46 | } |
|
47 | ||
48 | return __DIR__.'/../stubs/model.stub'; |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * Get the default namespace for the class. |
|
53 | * |
|
54 | * @param string $rootNamespace |
|
55 | * |
|
56 | * @return string |
|
57 | */ |
|
58 | protected function getDefaultNamespace($rootNamespace) |
|
59 | { |
|
60 | return $rootNamespace; |
|
61 | } |
|
62 | ||
63 | /** |
|
64 | * Replace the table name for the given stub. |
|
65 | * |
|
66 | * @param string $stub |
|
67 | * @param string $name |
|
68 | * |
|
69 | * @return string |
|
70 | */ |
|
71 | protected function replaceTable(&$stub, $name) |
|
72 | { |
|
73 | $table = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_').'s'; |
|
74 | ||
75 | $stub = str_replace('DummyTable', $table, $stub); |
|
76 | ||
77 | return $this; |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * Build the class with the given name. |
|
82 | * |
|
83 | * @param string $name |
|
84 | * |
|
85 | * @return string |
|
86 | */ |
|
87 | protected function buildClass($name) |
|
88 | { |
|
89 | $stub = $this->files->get($this->getStub()); |
|
90 | ||
91 | return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name); |
|
92 | } |
|
93 | ||
94 | /** |
|
95 | * Get the console command options. |
|
96 | * |
|
97 | * @return array |
|
98 | */ |
|
99 | protected function getOptions() |
|
100 | { |
|
101 | return [ |
|
102 | ||
103 | ]; |
|
104 | } |
|
105 | } |
|
106 |