Passed
Push — master ( 9be91c...ccfb9c )
by Neil
02:21
created

MakeController::createController()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 15
rs 9.4285
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
It seems like info() 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 ignore-call  annotation

15
        $this->/** @scrutinizer ignore-call */ info('Creating a new Controller');
Loading history...
16
        $this->info('Creating ' . $module . ':' . $filename . ' Controller');
0 ignored issues
show
Bug introduced by
It seems like info() 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 ignore-call  annotation

16
        $this->/** @scrutinizer ignore-call */ info('Creating ' . $module . ':' . $filename . ' Controller');
Loading history...
17
        $this->createControllersFolder($module);
18
        if (!file_exists(base_path() . "/app/Modules/" . $module . "/Controllers/" . $filename . ".php")) {
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
Bug introduced by
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 ignore-call  annotation

23
            (file_exists(base_path() . "/app/Modules/" . $module . "/Controllers/" . $filename . ".php") ? $this->info('Done'):$this->/** @scrutinizer ignore-call */ error('An error occurred'));
Loading history...
Bug introduced by
It seems like info() 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 ignore-call  annotation

23
            (file_exists(base_path() . "/app/Modules/" . $module . "/Controllers/" . $filename . ".php") ? $this->/** @scrutinizer ignore-call */ info('Done'):$this->error('An error occurred'));
Loading history...
24
            return;
25
        }
26
        $this->error('Controller already exists');
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

26
        $this->/** @scrutinizer ignore-call */ error('Controller already exists');
Loading history...
27
        return;
28
    }
29
30
    /**
31
     * @param $module
32
     */
33
    protected function createControllersFolder($module)
34
    {
35
        $this->createFolderInModule($module, "Controllers");
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

35
        $this->/** @scrutinizer ignore-call */ createFolderInModule($module, "Controllers");
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.stub';
46
47
        if ($this->option('plain')) {
0 ignored issues
show
Bug introduced by
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 ignore-call  annotation

47
        if ($this->/** @scrutinizer ignore-call */ option('plain')) {
Loading history...
48
            $stub = __DIR__ . '/../Stubs/controller.plain.stub';
49
        }
50
51
        return str_replace(
52
            ['DummyNamespace', 'DummyClass', 'DummyRootNamespaceHttp'],
53
            [App::getNamespace() . 'Modules\\' . $moduleName . '\Controllers', $className, App::getNamespace() .'Http'],
54
            file_get_contents($stub)
55
        );
56
    }
57
58
}