Passed
Push — master ( f58930...c354c0 )
by Mohammad
03:23
created
src/Commands/Generator.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function handle()
62 62
     {
63
-        $file = preg_split( " (/|\\\\) ", (string)$this->argument('name')) ?? [];
63
+        $file = preg_split(" (/|\\\\) ", (string) $this->argument('name')) ?? [];
64 64
 
65
-        if(!$file) return "Something wrong with the inputs !";
65
+        if (!$file) return "Something wrong with the inputs !";
66 66
 
67 67
         $this->repoName = $file[count($file) - 1];
68 68
 
69 69
         unset($file[count($file) - 1]);
70 70
         $path = implode("\\", $file);
71 71
 
72
-        if($this->option('only-view'))
72
+        if ($this->option('only-view'))
73 73
         {
74 74
             $this->makeViewsAndLanguage($path);
75 75
             return null;
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 
81 81
     function makeRepositoryPatternFiles($path)
82 82
     {
83
-        $model= str_plural(\Config::get('repository.model'));
84
-        $interface= str_plural(\Config::get('repository.interface'));
85
-        $repository= str_plural(\Config::get('repository.repository'));
83
+        $model = str_plural(\Config::get('repository.model'));
84
+        $interface = str_plural(\Config::get('repository.interface'));
85
+        $repository = str_plural(\Config::get('repository.repository'));
86 86
 
87 87
         $this->generate($path, \Config::get('repository.controllers_folder'), 'Controller');
88 88
         $this->generate($path, $model, 'Entity');
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         $this->generate($path, $interface, 'Interface');
91 91
         $this->generate($path, $repository, 'Repository');
92 92
 
93
-        File::append(\Config::get('repository.route_path') . '/web.php', "\n" . 'Route::resource(\'' . strtolower(str_plural($this->repoName)) . "', '".$path."\\".$this->repoName."Controller');");
93
+        File::append(\Config::get('repository.route_path') . '/web.php', "\n" . 'Route::resource(\'' . strtolower(str_plural($this->repoName)) . "', '" . $path . "\\" . $this->repoName . "Controller');");
94 94
     }
95 95
 
96 96
     /**
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 
104 104
         $createHtml = '';
105 105
         $editHtml = '';
106
-        if($entity instanceof Model)
106
+        if ($entity instanceof Model)
107 107
         {
108 108
             $createHtml = $this->FormGenerator->generateForm($entity);
109
-            $editHtml = $this->FormGenerator->generateForm($entity,'put');
109
+            $editHtml = $this->FormGenerator->generateForm($entity, 'put');
110 110
         }
111 111
         else
112 112
         {
113
-            if(!$this->confirm('There is no entity for '.$this->repoName.", do you want to continue (this will disable form generator) ?"))
113
+            if (!$this->confirm('There is no entity for ' . $this->repoName . ", do you want to continue (this will disable form generator) ?"))
114 114
             {
115 115
                 echo "Dispatch ..";
116 116
                 die;
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 
120 120
         foreach (\Config::get('repository.languages') as $lang)
121 121
         {
122
-            $this->generate(lcfirst($this->repoName),\Config::get('repository.lang_path')."/{$lang}" , 'lang');
122
+            $this->generate(lcfirst($this->repoName), \Config::get('repository.lang_path') . "/{$lang}", 'lang');
123 123
         }
124
-        $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'create',$createHtml);
125
-        $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'edit',$editHtml);
126
-        $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'index');
127
-        $this->generate(lcfirst($this->repoName),\Config::get('repository.resources_path')."/views" , 'show');
124
+        $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'create', $createHtml);
125
+        $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'edit', $editHtml);
126
+        $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'index');
127
+        $this->generate(lcfirst($this->repoName), \Config::get('repository.resources_path') . "/views", 'show');
128 128
     }
129 129
 
130 130
     /**
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
      */
135 135
     function getEntity($path)
136 136
     {
137
-        $myClass = 'App\Entities\\'.$path."\\".$this->repoName;
138
-        if(!class_exists($myClass))
137
+        $myClass = 'App\Entities\\' . $path . "\\" . $this->repoName;
138
+        if (!class_exists($myClass))
139 139
             return false;
140 140
 
141 141
         $refl = new ReflectionClass($myClass);
@@ -161,13 +161,13 @@  discard block
 block discarded – undo
161 161
      * @param string $form
162 162
      * @return bool
163 163
      */
164
-    protected function generate($path, $folder, $type,$form ='')
164
+    protected function generate($path, $folder, $type, $form = '')
165 165
     {
166 166
         $content = $this->getStub($type);
167 167
 
168
-        if($content === false)
168
+        if ($content === false)
169 169
         {
170
-            echo 'file '.$type.".stub is not exist !";
170
+            echo 'file ' . $type . ".stub is not exist !";
171 171
             return false;
172 172
         }
173 173
 
@@ -186,21 +186,21 @@  discard block
 block discarded – undo
186 186
                 str_plural(lcfirst($this->repoName)),
187 187
                 str_plural($folder),
188 188
                 $path,
189
-                str_plural(\Config::get('repository.model','Entity')),
190
-                str_plural(\Config::get('repository.interface','Interface')),
189
+                str_plural(\Config::get('repository.model', 'Entity')),
190
+                str_plural(\Config::get('repository.interface', 'Interface')),
191 191
                 $form
192 192
             ],
193 193
             $this->getStub($type)
194 194
         );
195 195
 
196
-        $folder = str_replace('\\','/',$folder);
197
-        $path = str_replace('\\','/',$path);
196
+        $folder = str_replace('\\', '/', $folder);
197
+        $path = str_replace('\\', '/', $path);
198 198
         
199 199
         switch ($type)
200 200
         {
201 201
             case 'Entity':
202 202
                 $filePath = $this->getFolderOrCreate(\Config::get('repository.app_path') . "/{$folder}/{$path}");
203
-                $filePath = rtrim($filePath,'/');
203
+                $filePath = rtrim($filePath, '/');
204 204
                 $filePath .= "/";
205 205
                 file_put_contents($filePath . "{$this->repoName}.php", $template);
206 206
                 break;
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
             case 'Repository':
210 210
             case 'Interface':
211 211
                 $filePath = $this->getFolderOrCreate(\Config::get('repository.app_path') . "/{$folder}/{$path}");
212
-                $filePath = rtrim($filePath,'/');
212
+                $filePath = rtrim($filePath, '/');
213 213
                 $filePath .= "/";
214 214
                 file_put_contents($filePath . "{$this->repoName}{$type}.php", $template);
215 215
                 break;
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
             case 'edit':
218 218
             case 'index':
219 219
             case 'show':
220
-                $filePath = $this->getFolderOrCreate($folder."/".str_plural($path))."/";
220
+                $filePath = $this->getFolderOrCreate($folder . "/" . str_plural($path)) . "/";
221 221
                 $repoName = lcfirst($type);
222
-                file_put_contents($filePath . $repoName.".blade.php", $template);
222
+                file_put_contents($filePath . $repoName . ".blade.php", $template);
223 223
             break;
224 224
             default:
225
-                $filePath = $this->getFolderOrCreate($folder)."/";
225
+                $filePath = $this->getFolderOrCreate($folder) . "/";
226 226
                 $repoName = lcfirst($this->repoName);
227
-                file_put_contents($filePath . $repoName.".php", $template);
227
+                file_put_contents($filePath . $repoName . ".php", $template);
228 228
         }
229 229
         return true;
230 230
     }
Please login to merge, or discard this patch.