Passed
Push — master ( d76988...9ef119 )
by Prateek
04:31 queued 02:30
created

Route::generate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 33
nc 1
nop 0
dl 0
loc 51
rs 9.392
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Prateekkarki\Laragen\Generators;
4
5
use Prateekkarki\Laragen\Models\Module;
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
        $webAuthRouteFile = $this->getPath("routes/backend/")."auth.php";
17
        $webRouteFile = $this->getPath("routes/frontend/")."web.php";
18
        $backendWebRouteFile = $this->getPath("routes/backend/")."web.php";
19
20
        $this->initializeFiles([
21
            $routeProviderFile => "RouteServiceProvider",
22
            $webAuthRouteFile => "Routes/Backend-auth",
23
            $webRouteFile => "Route",
24
            $backendWebRouteFile => "Routes/Backend-web"
25
        ]);
26
        
27
        $this->insertIntoFile(
28
            $routeProviderFile,
29
            $this->getStub('fragments/RouteMap'),
30
            "\n".$this->getStub('fragments/RouteMapCode')
31
        );
32
33
        $this->insertIntoFile(
34
            $webRouteFile,
35
            "<?php\n",
36
			"use App\\Http\\Controllers\\".$this->module->getModelName()."Controller;\n"
37
		);
38
39
        $this->insertIntoFile(
40
            $webRouteFile,
41
            "/" . "* Insert your routes here */",
42
            "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);"
43
        );
44
45
		$generatedFiles[] = $webRouteFile;
46
		
47
        $this->insertIntoFile(
48
            $backendWebRouteFile,
49
            "<?php\n",
50
			"use App\\Http\\Controllers\\".$this->module->getModelName()."Controller;\n"
51
		);
52
53
        $this->insertIntoFile(
54
            $backendWebRouteFile,
55
            "/" . "* Insert your routes here */",
56
            "\n".$this->getTabs(1)."Route::resource('".$this->module->getModuleName()."', ".$this->module->getModelName()."Controller::class);"
57
        );
58
59
        $generatedFiles[] = $backendWebRouteFile;
60
        
61
        return $generatedFiles;         
62
    }
63
}
64