Passed
Push — master ( 4e0c2f...af0465 )
by Prateek
04:42 queued 02:26
created

Route   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 37
dl 0
loc 60
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 56 2
1
<?php
2
namespace Prateekkarki\Laragen\Generators\Common;
3
4
use Prateekkarki\Laragen\Generators\BaseGenerator;
5
use Prateekkarki\Laragen\Generators\GeneratorInterface;
6
7
class Route extends BaseGenerator implements GeneratorInterface
8
{
9
    protected static $initializeFlag = 0;
10
11
    public function generate()
12
    {
13
        $generatedFiles = [];
14
15
        $routeProviderFile = $this->getPath("app/Providers/")."LaragenRouteServiceProvider.php";
16
        $backendAuthRouteFile = $this->getPath("routes/backend/")."auth.php";
17
        $webRouteFile = $this->getPath("routes/frontend/")."web.php";
18
        $backendWebRouteFile = $this->getPath("routes/backend/")."web.php";
19
20
        if(self::$initializeFlag++ == 0){
21
            $this->initializeFiles([
22
                $webRouteFile => "Route",
23
                $backendAuthRouteFile => "Routes/Backend-auth",
24
                $backendWebRouteFile => "Routes/Backend-web"
25
            ]);
26
        }
27
        
28
        $this->initializeFiles([
29
            $routeProviderFile => "RouteServiceProvider",
30
        ]);
31
32
        $this->insertIntoFile(
33
            $routeProviderFile,
34
            $this->getStub('fragments/RouteMap'),
35
            "\n".$this->getStub('fragments/RouteMapCode')
36
        );
37
38
        $this->insertIntoFile(
39
            $webRouteFile,
40
            "<?php\n",
41
			"use App\\Http\\Controllers\\".$this->module->getModelName()."Controller;\n"
42
		);
43
44
        $this->insertIntoFile(
45
            $webRouteFile,
46
            "/" . "* Insert your routes here */",
47
            "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);"
48
        );
49
50
		$generatedFiles[] = $webRouteFile;
51
		
52
        $this->insertIntoFile(
53
            $backendWebRouteFile,
54
            "<?php\n",
55
			"use App\\Http\\Controllers\\Backend\\".$this->module->getModelName()."Controller;\n"
56
		);
57
58
        $this->insertIntoFile(
59
            $backendWebRouteFile,
60
            "/" . "* Insert your routes here */",
61
            "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);"
62
        );
63
        
64
        $generatedFiles[] = $backendWebRouteFile;
65
        
66
        return $generatedFiles;         
67
    }
68
}
69