MakeRoutes   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createWebRoutesFile() 0 3 1
A createApiRoutesFile() 0 3 1
A createRoutesFile() 0 7 2
A compileRoutesStub() 0 6 1
1
<?php
2
3
namespace neilherbertuk\modules\Traits;
4
5
use Illuminate\Support\Facades\App;
6
7
trait MakeRoutes{
8
    /**
9
     * @param $module
10
     */
11
    protected function createWebRoutesFile($module)
12
    {
13
        $this->createRoutesFile($module, "web");
14
    }
15
16
    /**
17
     * @param $module
18
     */
19
    protected function createApiRoutesFile($module)
20
    {
21
        $this->createRoutesFile($module, "api");
22
    }
23
24
    /**
25
     * @param $module
26
     */
27
    protected function createRoutesFile($module, $type)
28
    {
29
        if (!file_exists(base_path() . "/app/Modules/" . $module . "/" . $type . ".php")) {
30
            $this->info("Creating $type routes file");
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

30
            $this->/** @scrutinizer ignore-call */ 
31
                   info("Creating $type routes file");
Loading history...
31
            file_put_contents(
32
                base_path() . "/app/Modules/" . $module . "/" . $type . ".php",
33
                $this->compileRoutesStub($module, $type)
34
            );
35
        }
36
    }
37
38
    /**
39
     * @param $module
40
     * @param $type
41
     * @return mixed
42
     */
43
    protected function compileRoutesStub($module, $type)
44
    {
45
        return str_replace(
46
            ['{{moduleName}}', '{{routeType}}'],
47
            [$module, $type],
48
            file_get_contents(__DIR__ . '/../Stubs/route.stub')
49
        );
50
    }
51
}
52