Completed
Pull Request — master (#53)
by
unknown
01:35
created
src/Commands/PublishCommand.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@
 block discarded – undo
6 6
 
7 7
 class PublishCommand extends Command {
8 8
 
9
-	protected $signature = 'wn:publish
9
+    protected $signature = 'wn:publish
10 10
         {--f : force the publishing.}
11 11
     ';
12
-	protected $description = 'Publishes the laravel-generators config file to the config folder of your project';
12
+    protected $description = 'Publishes the laravel-generators config file to the config folder of your project';
13 13
     protected $fs;
14 14
 
15 15
     public function __construct(Filesystem $fs)
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -23,22 +23,22 @@
 block discarded – undo
23 23
     {
24 24
         $paths = ServiceProvider::pathsToPublish('Wn\Generators\CommandsServiceProvider');
25 25
         
26
-        foreach($paths as $from => $to){
26
+        foreach ($paths as $from => $to) {
27 27
             $shortFrom = $this->shortPath($from);
28 28
             
29
-            if($this->copyFile($from, $to)) {
29
+            if ($this->copyFile($from, $to)) {
30 30
                 $this->info($shortFrom . ' has succesfully been copied to ' . $this->shortPath($to));
31
-            }else{
31
+            } else {
32 32
                 $this->warn($shortFrom . ' could not be copied. To try and force use the --f option.');
33 33
             }
34 34
         }
35 35
     }
36 36
     
37
-    private function shortPath($path){
37
+    private function shortPath($path) {
38 38
         return str_replace(base_path(), '', realpath($path));
39 39
     }
40 40
     
41
-    private function copyFile($from, $to){
41
+    private function copyFile($from, $to) {
42 42
         if ($this->fs->exists($to) && !$this->option('f')) {
43 43
             return false;
44 44
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@
 block discarded – undo
28 28
             
29 29
             if($this->copyFile($from, $to)) {
30 30
                 $this->info($shortFrom . ' has succesfully been copied to ' . $this->shortPath($to));
31
-            }else{
31
+            } else{
32 32
                 $this->warn($shortFrom . ' could not be copied. To try and force use the --f option.');
33 33
             }
34 34
         }
Please login to merge, or discard this patch.
src/CommandsServiceProvider.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 {
7 7
     public function boot()
8 8
     {
9
-        $configPath = __DIR__.'/../config/lumen-generators.php';
9
+        $configPath = __DIR__ . '/../config/lumen-generators.php';
10 10
         $this->publishes([
11 11
             $configPath => base_path('config/lumen-generators.php'),
12 12
         ]);
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     
15 15
     public function register()
16 16
     {
17
-        $configPath = __DIR__.'/../config/lumen-generators.php';
17
+        $configPath = __DIR__ . '/../config/lumen-generators.php';
18 18
         $this->mergeConfigFrom($configPath, 'lumen-generators');
19 19
 
20 20
         $this->registerPublishCommand();
@@ -32,92 +32,92 @@  discard block
 block discarded – undo
32 32
         // registerTestCommand
33 33
     }
34 34
 
35
-    protected function registerPublishCommand(){
36
-        $this->app->singleton('command.wn.publish', function($app){
35
+    protected function registerPublishCommand() {
36
+        $this->app->singleton('command.wn.publish', function($app) {
37 37
             return $app['Wn\Generators\Commands\PublishCommand'];
38 38
         });
39 39
         $this->commands('command.wn.publish');
40 40
     }
41 41
 
42
-    protected function registerModelCommand(){
43
-        $this->app->singleton('command.wn.model', function($app){
42
+    protected function registerModelCommand() {
43
+        $this->app->singleton('command.wn.model', function($app) {
44 44
             return $app['Wn\Generators\Commands\ModelCommand'];
45 45
         });
46 46
         $this->commands('command.wn.model');
47 47
     }
48 48
 
49
-    protected function registerControllerRestActionsCommand(){
50
-        $this->app->singleton('command.wn.controller.rest-actions', function($app){
49
+    protected function registerControllerRestActionsCommand() {
50
+        $this->app->singleton('command.wn.controller.rest-actions', function($app) {
51 51
             return $app['Wn\Generators\Commands\ControllerRestActionsCommand'];
52 52
         });
53 53
         $this->commands('command.wn.controller.rest-actions');
54 54
     }
55 55
 
56
-    protected function registerControllerCommand(){
57
-        $this->app->singleton('command.wn.controller', function($app){
56
+    protected function registerControllerCommand() {
57
+        $this->app->singleton('command.wn.controller', function($app) {
58 58
             return $app['Wn\Generators\Commands\ControllerCommand'];
59 59
         });
60 60
         $this->commands('command.wn.controller');
61 61
     }
62 62
 
63
-    protected function registerMigrationCommand(){
64
-        $this->app->singleton('command.wn.migration', function($app){
63
+    protected function registerMigrationCommand() {
64
+        $this->app->singleton('command.wn.migration', function($app) {
65 65
             return $app['Wn\Generators\Commands\MigrationCommand'];
66 66
         });
67 67
         $this->commands('command.wn.migration');
68 68
     }
69 69
 
70
-    protected function registerRouteCommand(){
71
-        $this->app->singleton('command.wn.route', function($app){
70
+    protected function registerRouteCommand() {
71
+        $this->app->singleton('command.wn.route', function($app) {
72 72
             return $app['Wn\Generators\Commands\RouteCommand'];
73 73
         });
74 74
         $this->commands('command.wn.route');
75 75
     }
76 76
 
77
-    protected function registerTestCommand(){
78
-        $this->app->singleton('command.wn.test', function($app){
77
+    protected function registerTestCommand() {
78
+        $this->app->singleton('command.wn.test', function($app) {
79 79
             return $app['Wn\Generators\Commands\TestCommand'];
80 80
         });
81 81
         $this->commands('command.wn.test');
82 82
     }
83 83
 
84
-    protected function registerResourceCommand(){
85
-        $this->app->singleton('command.wn.resource', function($app){
84
+    protected function registerResourceCommand() {
85
+        $this->app->singleton('command.wn.resource', function($app) {
86 86
             return $app['Wn\Generators\Commands\ResourceCommand'];
87 87
         });
88 88
         $this->commands('command.wn.resource');
89 89
     }
90 90
 
91
-    protected function registerResourcesCommand(){
92
-        $this->app->singleton('command.wn.resources', function($app){
91
+    protected function registerResourcesCommand() {
92
+        $this->app->singleton('command.wn.resources', function($app) {
93 93
             return $app['Wn\Generators\Commands\ResourcesCommand'];
94 94
         });
95 95
         $this->commands('command.wn.resources');
96 96
     }
97 97
 
98
-    protected function registerPivotTableCommand(){
99
-        $this->app->singleton('command.wn.pivot-table', function($app){
98
+    protected function registerPivotTableCommand() {
99
+        $this->app->singleton('command.wn.pivot-table', function($app) {
100 100
             return $app['Wn\Generators\Commands\PivotTableCommand'];
101 101
         });
102 102
         $this->commands('command.wn.pivot-table');
103 103
     }
104 104
 
105
-    protected function registerFactoryCommand(){
106
-        $this->app->singleton('command.wn.factory', function($app){
105
+    protected function registerFactoryCommand() {
106
+        $this->app->singleton('command.wn.factory', function($app) {
107 107
             return $app['Wn\Generators\Commands\FactoryCommand'];
108 108
         });
109 109
         $this->commands('command.wn.factory');
110 110
     }
111 111
 
112
-    protected function registerSeederCommand(){
113
-        $this->app->singleton('command.wn.seeder', function($app){
112
+    protected function registerSeederCommand() {
113
+        $this->app->singleton('command.wn.seeder', function($app) {
114 114
             return $app['Wn\Generators\Commands\SeederCommand'];
115 115
         });
116 116
         $this->commands('command.wn.seeder');
117 117
     }
118 118
 
119
-    protected function registerPivotSeederCommand(){
120
-        $this->app->singleton('command.wn.pivot.seeder', function($app){
119
+    protected function registerPivotSeederCommand() {
120
+        $this->app->singleton('command.wn.pivot.seeder', function($app) {
121 121
             return $app['Wn\Generators\Commands\PivotSeederCommand'];
122 122
         });
123 123
         $this->commands('command.wn.pivot.seeder');
Please login to merge, or discard this patch.
src/Commands/ModelCommand.php 2 patches
Doc Comments   +10 added lines patch added patch discarded remove patch
@@ -43,6 +43,9 @@  discard block
 block discarded – undo
43 43
         $this->save($content, "./{$path}/{$name}.php", "{$name} model");
44 44
     }
45 45
 
46
+    /**
47
+     * @param string $rule
48
+     */
46 49
     protected function getFieldByRuleAsArrayFields($rule, $allowPartialMatch = false)
47 50
     {
48 51
         $rules = $this->getRules(false);
@@ -63,6 +66,9 @@  discard block
 block discarded – undo
63 66
         }, $fields));
64 67
     }
65 68
 
69
+    /**
70
+     * @param string $arg
71
+     */
66 72
     protected function getAsArrayFields($arg, $isOption = true)
67 73
     {
68 74
     	$arg = ($isOption) ? $this->option($arg) : $this->argument($arg);
@@ -97,6 +103,10 @@  discard block
 block discarded – undo
97 103
         return implode(PHP_EOL, $relations);
98 104
     }
99 105
 
106
+    /**
107
+     * @param string $type
108
+     * @param string $option
109
+     */
100 110
     protected function getRelationsByType($type, $option, $withTimestamps = false)
101 111
     {
102 112
         $relations = [];
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -48,17 +48,17 @@  discard block
 block discarded – undo
48 48
         $rules = $this->getRules(false);
49 49
         $fields = [];
50 50
                 
51
-        foreach($rules as $ruleId => $ruleData){
51
+        foreach ($rules as $ruleId => $ruleData) {
52 52
             $fieldRules = explode(',', $ruleData['rule']);
53 53
             
54
-            foreach($fieldRules as $fieldRule){
55
-                if($fieldRule === $rule || str_contains($fieldRule, $rule)){
54
+            foreach ($fieldRules as $fieldRule) {
55
+                if ($fieldRule === $rule || str_contains($fieldRule, $rule)) {
56 56
                     $fields[] = $ruleData['name'];
57 57
                 }
58 58
             }
59 59
         }
60 60
         
61
-        return implode(', ', array_map(function($item){
61
+        return implode(', ', array_map(function($item) {
62 62
             return '"' . $item . '"';
63 63
         }, $fields));
64 64
     }
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
     protected function getAsArrayFields($arg, $isOption = true)
67 67
     {
68 68
     	$arg = ($isOption) ? $this->option($arg) : $this->argument($arg);
69
-        if(is_string($arg)){
69
+        if (is_string($arg)) {
70 70
         	$arg = explode(',', $arg);
71
-        } else if(! is_array($arg)) {
71
+        } else if (!is_array($arg)) {
72 72
             $arg = [];
73 73
         }
74
-        return implode(', ', array_map(function($item){
74
+        return implode(', ', array_map(function($item) {
75 75
             return '"' . $item . '"';
76 76
         }, $arg));
77 77
     }
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
             $this->getRelationsByType('belongsToMany', 'belongs-to-many', true)
91 91
         );
92 92
 
93
-        if(empty($relations)){
93
+        if (empty($relations)) {
94 94
             return "    // Relationships";
95 95
         }
96 96
 
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     {
102 102
         $relations = [];
103 103
         $option = $this->option($option);
104
-        if($option){
104
+        if ($option) {
105 105
 
106 106
             $items = $this->getArgumentParser('relations')->parse($option);
107 107
 
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
             $template = $this->getTemplate($template);
110 110
             foreach ($items as $item) {
111 111
                 $item['type'] = $type;
112
-                if(! $item['model']){
112
+                if (!$item['model']) {
113 113
                     $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['name']));
114
-                } else if(strpos($item['model'], '\\') === false ){
114
+                } else if (strpos($item['model'], '\\') === false) {
115 115
                     $item['model'] = $this->getNamespace() . '\\' . $item['model'];
116 116
                 }
117 117
                 $relations[] = $template->with($item)->get();
@@ -123,11 +123,11 @@  discard block
 block discarded – undo
123 123
     protected function getRules($inTemplate = true)
124 124
     {
125 125
         $rules = $this->option('rules');
126
-        if(! $rules){
126
+        if (!$rules) {
127 127
             return "        // Validation rules";
128 128
         }
129 129
         $items = $rules;
130
-        if(! $this->option('parsed')){
130
+        if (!$this->option('parsed')) {
131 131
             $items = $this->getArgumentParser('rules')->parse($rules);
132 132
         }
133 133
         $model = $this->argument('name');
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         foreach ($items as $item) {
137 137
             $rules[] = $template->with(array_merge(
138 138
                 $item,
139
-                [ 'model' => $model ]
139
+                ['model' => $model]
140 140
             ))->get();
141 141
         }
142 142
 
Please login to merge, or discard this patch.
src/Commands/ControllerCommand.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -5,34 +5,34 @@
 block discarded – undo
5 5
 
6 6
 class ControllerCommand extends BaseCommand {
7 7
 
8
-	protected $signature = 'wn:controller
8
+    protected $signature = 'wn:controller
9 9
         {model : Name of the model (with namespace if not App)}
10 10
 		{--no-routes= : without routes}
11 11
         {--force= : override the existing files}
12 12
         {--laravel : Use Laravel style route definitions}
13 13
     ';
14 14
 
15
-	protected $description = 'Generates RESTful controller using the RESTActions trait';
15
+    protected $description = 'Generates RESTful controller using the RESTActions trait';
16 16
 
17 17
     public function handle()
18 18
     {
19
-    	$model = $this->argument('model');
20
-    	$name = '';
21
-    	if(strrpos($model, "\\") === false){
22
-    		$name = $model;
23
-    		$model = "App\\" . $model;
24
-    	} else {
25
-    		$name = explode("\\", $model);
26
-    		$name = $name[count($name) - 1];
27
-    	}
19
+        $model = $this->argument('model');
20
+        $name = '';
21
+        if(strrpos($model, "\\") === false){
22
+            $name = $model;
23
+            $model = "App\\" . $model;
24
+        } else {
25
+            $name = explode("\\", $model);
26
+            $name = $name[count($name) - 1];
27
+        }
28 28
         $controller = ucwords(str_plural($name)) . 'Controller';
29 29
         $content = $this->getTemplate('controller')
30
-        	->with([
31
-        		'name' => $controller,
32
-        		'model' => $model,
30
+            ->with([
31
+                'name' => $controller,
32
+                'model' => $model,
33 33
                 'model_name' => $name
34
-        	])
35
-        	->get();
34
+            ])
35
+            ->get();
36 36
 
37 37
         $this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
38 38
         if(! $this->option('no-routes')){
Please login to merge, or discard this patch.
src/Template/TemplateLoader.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@
 block discarded – undo
7 7
 
8 8
 class TemplateLoader {
9 9
 	
10
-	protected $fs;
10
+    protected $fs;
11 11
 
12
-	protected $loaded;
12
+    protected $loaded;
13 13
 
14
-	public function __construct(Filesystem $fs)
15
-	{
16
-		$this->fs = $fs;
17
-		$this->loaded = [];
18
-	}
14
+    public function __construct(Filesystem $fs)
15
+    {
16
+        $this->fs = $fs;
17
+        $this->loaded = [];
18
+    }
19 19
 
20
-	public function load($name)
21
-	{
22
-		if(! isset($this->loaded[$name])){
23
-			$path = config("lumen-generators.custom_templates.{$name}", __DIR__ . "/../../templates/{$name}.wnt");
20
+    public function load($name)
21
+    {
22
+        if(! isset($this->loaded[$name])){
23
+            $path = config("lumen-generators.custom_templates.{$name}", __DIR__ . "/../../templates/{$name}.wnt");
24 24
 			
25
-			try {
26
-				$this->loaded[$name] = $this->fs->get($path);
27
-			} catch(\Exception $e) {
28
-				throw new TemplateException("Unable to read the file '{$path}'");
29
-			}
30
-		}
31
-		return new Template($this, $this->loaded[$name]);
32
-	}
25
+            try {
26
+                $this->loaded[$name] = $this->fs->get($path);
27
+            } catch(\Exception $e) {
28
+                throw new TemplateException("Unable to read the file '{$path}'");
29
+            }
30
+        }
31
+        return new Template($this, $this->loaded[$name]);
32
+    }
33 33
 
34 34
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,12 +19,12 @@
 block discarded – undo
19 19
 
20 20
 	public function load($name)
21 21
 	{
22
-		if(! isset($this->loaded[$name])){
22
+		if (!isset($this->loaded[$name])) {
23 23
 			$path = config("lumen-generators.custom_templates.{$name}", __DIR__ . "/../../templates/{$name}.wnt");
24 24
 			
25 25
 			try {
26 26
 				$this->loaded[$name] = $this->fs->get($path);
27
-			} catch(\Exception $e) {
27
+			} catch (\Exception $e) {
28 28
 				throw new TemplateException("Unable to read the file '{$path}'");
29 29
 			}
30 30
 		}
Please login to merge, or discard this patch.