neilherbertuk /
modules
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace neilherbertuk\modules\Traits; |
||||||
| 4 | |||||||
| 5 | use Illuminate\Support\Facades\App; |
||||||
| 6 | |||||||
| 7 | trait MakeController{ |
||||||
| 8 | |||||||
| 9 | /** |
||||||
| 10 | * @param $module |
||||||
| 11 | * @param $filename |
||||||
| 12 | */ |
||||||
| 13 | protected function createController($module, $filename) |
||||||
| 14 | { |
||||||
| 15 | $this->info("Creating a new Controller"); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 16 | $this->info("Creating $module:$filename Controller"); |
||||||
| 17 | $this->createControllersFolder($module); |
||||||
| 18 | if (!file_exists(base_path() . "/app/Modules/" . $module . "/Controllers/" . $filename . ".php")) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 19 | file_put_contents( |
||||||
| 20 | base_path() . "/app/Modules/" . $module . "/Controllers/" . $filename . ".php", |
||||||
| 21 | $this->compileControllerStub($module, $filename) |
||||||
| 22 | ); |
||||||
| 23 | (file_exists(base_path() . "/app/Modules/" . $module . "/Controllers/" . $filename . ".php") ? $this->info('Done'):$this->error('An error occurred')); |
||||||
|
0 ignored issues
–
show
It seems like
error() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 24 | return; |
||||||
| 25 | } |
||||||
| 26 | $this->error("Controller already exists"); |
||||||
| 27 | return; |
||||||
| 28 | } |
||||||
| 29 | |||||||
| 30 | /** |
||||||
| 31 | * @param $module |
||||||
| 32 | */ |
||||||
| 33 | protected function createControllersFolder($module) |
||||||
| 34 | { |
||||||
| 35 | $this->createFolderInModule($module, "Controllers"); |
||||||
|
0 ignored issues
–
show
It seems like
createFolderInModule() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 36 | } |
||||||
| 37 | |||||||
| 38 | /** |
||||||
| 39 | * @param $moduleName |
||||||
| 40 | * @param $className |
||||||
| 41 | * @return mixed |
||||||
| 42 | */ |
||||||
| 43 | protected function compileControllerStub($moduleName, $className) |
||||||
| 44 | { |
||||||
| 45 | $stub = __DIR__ . '/../Stubs/controller.plain.stub'; |
||||||
| 46 | |||||||
| 47 | if ($this->option('resource')) { |
||||||
|
0 ignored issues
–
show
It seems like
option() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | $stub = __DIR__ . '/../Stubs/controller.stub'; |
||||||
| 49 | } |
||||||
| 50 | |||||||
| 51 | return str_replace( |
||||||
| 52 | ['DummyNamespace', 'DummyClass', 'DummyRootNamespaceHttp'], |
||||||
| 53 | [App::getNamespace() . 'Modules\\' . $moduleName . '\Controllers', $className, App::getNamespace() .'Http'], |
||||||
|
0 ignored issues
–
show
|
|||||||
| 54 | file_get_contents($stub) |
||||||
| 55 | ); |
||||||
| 56 | } |
||||||
| 57 | |||||||
| 58 | } |