@@ -19,11 +19,11 @@ |
||
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 = __DIR__ . "/../../templates/{$name}.wnt"; |
24 | 24 | try { |
25 | 25 | $this->loaded[$name] = $this->fs->get($path); |
26 | - } catch(\Exception $e) { |
|
26 | + } catch (\Exception $e) { |
|
27 | 27 | throw new TemplateException("Unable to read the file '{$path}'"); |
28 | 28 | } |
29 | 29 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function with($data = []) |
35 | 35 | { |
36 | - if($data) |
|
36 | + if ($data) |
|
37 | 37 | $this->dirty = true; |
38 | 38 | foreach ($data as $key => $value) { |
39 | 39 | $this->data[$key] = $value; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | |
44 | 44 | public function get() |
45 | 45 | { |
46 | - if($this->dirty){ |
|
46 | + if ($this->dirty) { |
|
47 | 47 | $this->compile(); |
48 | 48 | $this->dirty = false; |
49 | 49 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | public function compile() |
54 | 54 | { |
55 | 55 | $this->compiled = $this->text; |
56 | - foreach($this->data as $key => $value){ |
|
56 | + foreach ($this->data as $key => $value) { |
|
57 | 57 | $this->compiled = str_replace('{{' . $key . '}}', $value, $this->compiled); |
58 | 58 | } |
59 | 59 | return $this; |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | $resource = $this->argument('resource'); |
15 | 15 | |
16 | 16 | $routesPath = './routes/web.php'; |
17 | - if (! $this->fs->exists($routesPath)) |
|
17 | + if (!$this->fs->exists($routesPath)) |
|
18 | 18 | $routesPath = './app/Http/routes.php'; |
19 | 19 | |
20 | 20 | $content = $this->fs->get($routesPath); |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | protected function getController() |
33 | 33 | { |
34 | 34 | $controller = $this->option('controller'); |
35 | - if(! $controller){ |
|
35 | + if (!$controller) { |
|
36 | 36 | $controller = ucwords(str_plural(camel_case($this->argument('resource')))) . 'Controller'; |
37 | 37 | } |
38 | 38 | return $controller; |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | protected function getAsArrayFields($arg, $isOption = true) |
44 | 44 | { |
45 | 45 | $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
46 | - if(is_string($arg)){ |
|
46 | + if (is_string($arg)) { |
|
47 | 47 | $arg = explode(',', $arg); |
48 | - } else if(! is_array($arg)) { |
|
48 | + } else if (!is_array($arg)) { |
|
49 | 49 | $arg = []; |
50 | 50 | } |
51 | - return implode(', ', array_map(function($item){ |
|
51 | + return implode(', ', array_map(function($item) { |
|
52 | 52 | return '"' . $item . '"'; |
53 | 53 | }, $arg)); |
54 | 54 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | $this->getRelationsByType('belongsToMany', 'belongs-to-many', true) |
68 | 68 | ); |
69 | 69 | |
70 | - if(empty($relations)){ |
|
70 | + if (empty($relations)) { |
|
71 | 71 | return " // Relationships"; |
72 | 72 | } |
73 | 73 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | { |
79 | 79 | $relations = []; |
80 | 80 | $option = $this->option($option); |
81 | - if($option){ |
|
81 | + if ($option) { |
|
82 | 82 | |
83 | 83 | $items = $this->getArgumentParser('relations')->parse($option); |
84 | 84 | |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | $template = $this->getTemplate($template); |
87 | 87 | foreach ($items as $item) { |
88 | 88 | $item['type'] = $type; |
89 | - if(! $item['model']){ |
|
89 | + if (!$item['model']) { |
|
90 | 90 | $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['name'])); |
91 | - } else if(strpos($item['model'], '\\') === false ){ |
|
91 | + } else if (strpos($item['model'], '\\') === false) { |
|
92 | 92 | $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
93 | 93 | } |
94 | 94 | $relations[] = $template->with($item)->get(); |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | protected function getRules() |
101 | 101 | { |
102 | 102 | $rules = $this->option('rules'); |
103 | - if(! $rules){ |
|
103 | + if (!$rules) { |
|
104 | 104 | return " // Validation rules"; |
105 | 105 | } |
106 | 106 | $items = $rules; |
107 | - if(! $this->option('parsed')){ |
|
107 | + if (!$this->option('parsed')) { |
|
108 | 108 | $items = $this->getArgumentParser('rules')->parse($rules); |
109 | 109 | } |
110 | 110 | $rules = []; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | $model = $this->argument('model'); |
17 | 17 | $name = ''; |
18 | - if(strrpos($model, "\\") === false){ |
|
18 | + if (strrpos($model, "\\") === false) { |
|
19 | 19 | $name = $model; |
20 | 20 | $model = "App\\" . $model; |
21 | 21 | } else { |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | |
33 | 33 | $this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}"); |
34 | 34 | |
35 | - if(! $this->option('no-routes')){ |
|
35 | + if (!$this->option('no-routes')) { |
|
36 | 36 | $this->call('wn:route', [ |
37 | 37 | 'resource' => snake_case($name, '-'), |
38 | 38 | '--controller' => $controller |
@@ -26,7 +26,7 @@ |
||
26 | 26 | return $this->templates->load($name); |
27 | 27 | } |
28 | 28 | |
29 | - protected function getArgumentParser($name){ |
|
29 | + protected function getArgumentParser($name) { |
|
30 | 30 | $format = $this->argumentFormatLoader->load($name); |
31 | 31 | return new ArgumentParser($format); |
32 | 32 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | ]); |
58 | 58 | |
59 | 59 | // generating REST actions trait if doesn't exist |
60 | - if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ |
|
60 | + if (!$this->fs->exists('./app/Http/Controllers/RESTActions.php')) { |
|
61 | 61 | $this->call('wn:controller:rest-actions'); |
62 | 62 | } |
63 | 63 | |
@@ -86,10 +86,10 @@ discard block |
||
86 | 86 | protected function parseFields() |
87 | 87 | { |
88 | 88 | $fields = $this->argument('fields'); |
89 | - if($this->option('parsed')){ |
|
89 | + if ($this->option('parsed')) { |
|
90 | 90 | $this->fields = $fields; |
91 | 91 | } else { |
92 | - if(! $fields){ |
|
92 | + if (!$fields) { |
|
93 | 93 | $this->fields = []; |
94 | 94 | } else { |
95 | 95 | $this->fields = $this->getArgumentParser('fields') |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | |
114 | 114 | protected function fieldsHavingTag($tag) |
115 | 115 | { |
116 | - return array_map(function($field){ |
|
116 | + return array_map(function($field) { |
|
117 | 117 | return $field['name']; |
118 | 118 | }, array_filter($this->fields, function($field) use($tag){ |
119 | 119 | return in_array($tag, $field['tags']); |
@@ -122,19 +122,19 @@ discard block |
||
122 | 122 | |
123 | 123 | protected function rules() |
124 | 124 | { |
125 | - return array_map(function($field){ |
|
125 | + return array_map(function($field) { |
|
126 | 126 | return [ |
127 | 127 | 'name' => $field['name'], |
128 | 128 | 'rule' => $field['rules'] |
129 | 129 | ]; |
130 | - }, array_filter($this->fields, function($field){ |
|
130 | + }, array_filter($this->fields, function($field) { |
|
131 | 131 | return !empty($field['rules']); |
132 | 132 | })); |
133 | 133 | } |
134 | 134 | |
135 | 135 | protected function schema() |
136 | 136 | { |
137 | - return array_map(function($field){ |
|
137 | + return array_map(function($field) { |
|
138 | 138 | return array_merge([[ |
139 | 139 | 'name' => $field['name'], |
140 | 140 | 'args' => [] |
@@ -145,14 +145,14 @@ discard block |
||
145 | 145 | protected function foreignKeys() |
146 | 146 | { |
147 | 147 | $belongsTo = $this->option('belongs-to'); |
148 | - if(! $belongsTo) { |
|
148 | + if (!$belongsTo) { |
|
149 | 149 | return []; |
150 | 150 | } |
151 | 151 | $relations = $this->getArgumentParser('relations')->parse($belongsTo); |
152 | - return array_map(function($relation){ |
|
152 | + return array_map(function($relation) { |
|
153 | 153 | $name = $relation['model'] ? $relation['model'] : $relation['name']; |
154 | 154 | $index = strrpos($name, "\\"); |
155 | - if($index) { |
|
155 | + if ($index) { |
|
156 | 156 | $name = substr($name, $index + 1); |
157 | 157 | } |
158 | 158 | return snake_case(str_singular($name)) . '_id'; |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | |
174 | 174 | protected function factoryFields() |
175 | 175 | { |
176 | - return array_map(function($field){ |
|
176 | + return array_map(function($field) { |
|
177 | 177 | return [ |
178 | 178 | 'name' => $field['name'], |
179 | 179 | 'type' => $field['factory'] |
180 | 180 | ]; |
181 | - }, array_filter($this->fields, function($field){ |
|
181 | + }, array_filter($this->fields, function($field) { |
|
182 | 182 | return isset($field['factory']) && $field['factory']; |
183 | 183 | })); |
184 | 184 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | protected function getFile() |
35 | 35 | { |
36 | 36 | $file = $this->option('file'); |
37 | - if(! $file){ |
|
37 | + if (!$file) { |
|
38 | 38 | $file = './database/factories/ModelFactory.php'; |
39 | 39 | } |
40 | 40 | return $file; |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | |
47 | 47 | $fields = $this->option('fields'); |
48 | 48 | |
49 | - if($fields){ |
|
50 | - if(! $this->option('parsed')){ |
|
49 | + if ($fields) { |
|
50 | + if (!$this->option('parsed')) { |
|
51 | 51 | $fields = $this->getArgumentParser('factory-fields')->parse($fields); |
52 | 52 | } |
53 | 53 | $template = $this->getTemplate('factory/field'); |
54 | - foreach($fields as $field){ |
|
54 | + foreach ($fields as $field) { |
|
55 | 55 | $content[] = $template->with($field)->get(); |
56 | 56 | } |
57 | 57 | $content = implode(PHP_EOL, $content); |
@@ -45,7 +45,7 @@ |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | protected function getSeederName($resources) { |
48 | - $resources = array_map(function($resource){ |
|
48 | + $resources = array_map(function($resource) { |
|
49 | 49 | return ucwords(camel_case($resource)); |
50 | 50 | }, $resources); |
51 | 51 | return implode('', $resources) . 'TableSeeder'; |