Completed
Pull Request — master (#71)
by
unknown
01:27
created
src/Commands/ResourceCommand.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php namespace Wn\Generators\Commands;
2 2
 
3 3
 
4
-use InvalidArgumentException;
5 4
 use Illuminate\Support\Str;
6 5
 
7 6
 class ResourceCommand extends BaseCommand {
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         ]);
63 63
 
64 64
         // generating REST actions trait if doesn't exist
65
-        if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){
65
+        if (!$this->fs->exists('./app/Http/Controllers/RESTActions.php')) {
66 66
             $this->call('wn:controller:rest-actions');
67 67
         }
68 68
         // generating the controller and routes
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
     protected function parseFields()
95 95
     {
96 96
         $fields = $this->argument('fields');
97
-        if($this->option('parsed')){
97
+        if ($this->option('parsed')) {
98 98
             $this->fields = $fields;
99 99
         } else {
100
-            if(! $fields){
100
+            if (!$fields) {
101 101
                 $this->fields = [];
102 102
             } else {
103 103
                 $this->fields = $this->getArgumentParser('fields')
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 
122 122
     protected function fieldsHavingTag($tag)
123 123
     {
124
-        return array_map(function($field){
124
+        return array_map(function($field) {
125 125
             return $field['name'];
126 126
         }, array_filter($this->fields, function($field) use($tag){
127 127
             return in_array($tag, $field['tags']);
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
 
131 131
     protected function rules()
132 132
     {
133
-        return array_map(function($field){
133
+        return array_map(function($field) {
134 134
             return [
135 135
                 'name' => $field['name'],
136 136
                 'rule' => $field['rules']
137 137
             ];
138
-        }, array_filter($this->fields, function($field){
138
+        }, array_filter($this->fields, function($field) {
139 139
             return !empty($field['rules']);
140 140
         }));
141 141
     }
142 142
 
143 143
     protected function schema()
144 144
     {
145
-        return array_map(function($field){
145
+        return array_map(function($field) {
146 146
             return array_merge([[
147 147
                 'name' => $field['name'],
148 148
                 'args' => []
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
     protected function foreignKeys()
154 154
     {
155 155
         $belongsTo = $this->option('belongs-to');
156
-        if(! $belongsTo) {
156
+        if (!$belongsTo) {
157 157
             return [];
158 158
         }
159 159
         $relations = $this->getArgumentParser('relations')->parse($belongsTo);
160
-        return array_map(function($relation){
160
+        return array_map(function($relation) {
161 161
             $name = $relation['model'] ? $relation['model'] : $relation['name'];
162 162
             $index = strrpos($name, "\\");
163
-            if($index) {
163
+            if ($index) {
164 164
                 $name = substr($name, $index + 1);
165 165
             }
166 166
             return Str::snake(Str::singular($name)) . '_id';
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
 
182 182
     protected function factoryFields()
183 183
     {
184
-        return array_map(function($field){
184
+        return array_map(function($field) {
185 185
             return [
186 186
                 'name' => $field['name'],
187 187
                 'type' => $field['factory']
188 188
             ];
189
-        }, array_filter($this->fields, function($field){
189
+        }, array_filter($this->fields, function($field) {
190 190
             return isset($field['factory']) && $field['factory'];
191 191
         }));
192 192
     }
Please login to merge, or discard this patch.
src/Commands/ResourcesCommand.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@
 block discarded – undo
1 1
 <?php namespace Wn\Generators\Commands;
2 2
 
3
-use InvalidArgumentException;
4 3
 use Symfony\Component\Yaml\Yaml;
5 4
 use Illuminate\Support\Str;
6 5
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
         $content = Yaml::parse($content);
26 26
 
27 27
         $modelIndex = 0;
28
-        foreach ($content as $model => $i){
28
+        foreach ($content as $model => $i) {
29 29
             $i = $this->getResourceParams($model, $i);
30
-            $migrationName = 'Create' .  ucwords(Str::plural($i['name']));
31
-            $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , 3, 0, STR_PAD_LEFT) . '_' . Str::snake($migrationName) . '_table';
30
+            $migrationName = 'Create' . ucwords(Str::plural($i['name']));
31
+            $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex, 3, 0, STR_PAD_LEFT) . '_' . Str::snake($migrationName) . '_table';
32 32
 
33 33
 
34 34
             $options = [
@@ -79,34 +79,34 @@  discard block
 block discarded – undo
79 79
     {
80 80
         $i['name'] = Str::snake($modelName);
81 81
 
82
-        foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany'] as $relation){
83
-            if(isset($i[$relation])){
82
+        foreach (['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany'] as $relation) {
83
+            if (isset($i[$relation])) {
84 84
                 $i[$relation] = $this->convertArray($i[$relation], ' ', ',');
85 85
             } else {
86 86
                 $i[$relation] = false;
87 87
             }
88 88
         }
89 89
 
90
-        if($i['belongsToMany']){
90
+        if ($i['belongsToMany']) {
91 91
             $relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']);
92
-            foreach ($relations as $relation){
92
+            foreach ($relations as $relation) {
93 93
                 $table = '';
94 94
 
95
-                if(! $relation['model']){
95
+                if (!$relation['model']) {
96 96
                     $table = Str::snake($relation['name']);
97 97
                 } else {
98 98
                     $names = array_reverse(explode("\\", $relation['model']));
99 99
                     $table = Str::snake($names[0]);
100 100
                 }
101 101
 
102
-                $tables = [ Str::singular($table), $i['name'] ];
102
+                $tables = [Str::singular($table), $i['name']];
103 103
                 sort($tables);
104 104
                 $this->pivotTables[] = $tables;
105 105
             }
106 106
         }
107 107
 
108 108
         $fields = [];
109
-        foreach($i['fields'] as $name => $value) {
109
+        foreach ($i['fields'] as $name => $value) {
110 110
             $value['name'] = $name;
111 111
             $fields[] = $this->serializeField($value);
112 112
         }
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 
128 128
         $string = "{$name};{$schema};{$rules};{$tags}";
129 129
 
130
-        if(isset($field['factory']) && !empty($field['factory'])){
130
+        if (isset($field['factory']) && !empty($field['factory'])) {
131 131
             $string .= ';' . $field['factory'];
132 132
         }
133 133
 
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
     protected function convertArray($list, $old, $new)
138 138
     {
139
-        return implode($new, array_filter(explode($old, $list), function($item){
139
+        return implode($new, array_filter(explode($old, $list), function($item) {
140 140
             return !empty($item);
141 141
         }));
142 142
     }
Please login to merge, or discard this patch.