MakeController::compileControllerStub()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
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 */ 
16
               info("Creating a new Controller");
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
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 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...
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...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 162 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...
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
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 */ 
36
               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.plain.stub';
46
47
        if ($this->option('resource')) {
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('resource')) {
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
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 120 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...
54
            file_get_contents($stub)
55
        );
56
    }
57
58
}