@@ -5,17 +5,17 @@ discard block |
||
| 5 | 5 | use Prateekkarki\Laragen\Models\TypeResolver; |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | - * The LaragenType abstract class. This class cannot be instantiated. It's implementations are used to create new types. |
|
| 9 | - * Column instances are created from types that are implementations of this class. |
|
| 10 | - * |
|
| 11 | - * @method integer getSize() |
|
| 12 | - * @method integer getDataType() |
|
| 13 | - * @method array getPivotColumns() |
|
| 14 | - * @method void setSize() |
|
| 15 | - * @method void setIsRequired() |
|
| 16 | - * @method void setIsUnique() |
|
| 17 | - * @method void setIsDisplay() |
|
| 18 | - */ |
|
| 8 | + * The LaragenType abstract class. This class cannot be instantiated. It's implementations are used to create new types. |
|
| 9 | + * Column instances are created from types that are implementations of this class. |
|
| 10 | + * |
|
| 11 | + * @method integer getSize() |
|
| 12 | + * @method integer getDataType() |
|
| 13 | + * @method array getPivotColumns() |
|
| 14 | + * @method void setSize() |
|
| 15 | + * @method void setIsRequired() |
|
| 16 | + * @method void setIsUnique() |
|
| 17 | + * @method void setIsDisplay() |
|
| 18 | + */ |
|
| 19 | 19 | abstract class LaragenType |
| 20 | 20 | { |
| 21 | 21 | /** |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | public function getTextRows() { |
| 214 | 214 | if (!$this->size) { |
| 215 | - return 4; |
|
| 215 | + return 4; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | return floor($this->getsize() / 120); |
@@ -63,19 +63,19 @@ |
||
| 63 | 63 | { |
| 64 | 64 | $this->name = $moduleName; |
| 65 | 65 | |
| 66 | - if(isset($moduleData['additional_fields'])){ |
|
| 66 | + if (isset($moduleData['additional_fields'])) { |
|
| 67 | 67 | $this->seoFields = $moduleData['additional_fields']['seo'] ?? config('laragen.options.seo_fields'); |
| 68 | 68 | $this->genericFields = $moduleData['additional_fields']['generic'] ?? config('laragen.options.generic_fields'); |
| 69 | 69 | unset($moduleData['additional_fields']); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - if(isset($moduleData['data'])){ |
|
| 72 | + if (isset($moduleData['data'])) { |
|
| 73 | 73 | $this->seedableData = $moduleData['data'] ?? null; |
| 74 | 74 | unset($moduleData['data']); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $moduleStructure = $moduleData['structure'] ?? (!empty($moduleData) ? $moduleData : ['title' => 'string|max:128']); |
| 78 | - if(isset($moduleData['structure'])){ |
|
| 78 | + if (isset($moduleData['structure'])) { |
|
| 79 | 79 | unset($moduleData['structure']); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -100,8 +100,9 @@ |
||
| 100 | 100 | foreach ($moduleStructure as $columnName => $columnOptions) { |
| 101 | 101 | $column = TypeResolver::getType($this->name, $columnName, $columnOptions); |
| 102 | 102 | $this->columnsData[$columnName] = $column; |
| 103 | - if ($column->isDisplay()) |
|
| 104 | - $this->displayColumns[] = $column; |
|
| 103 | + if ($column->isDisplay()) { |
|
| 104 | + $this->displayColumns[] = $column; |
|
| 105 | + } |
|
| 105 | 106 | } |
| 106 | 107 | |
| 107 | 108 | if (sizeof($this->displayColumns) == 0) { |
@@ -22,13 +22,13 @@ |
||
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | public function removeDir($dir) { |
| 25 | - if (! is_dir($dir)) { |
|
| 25 | + if (!is_dir($dir)) { |
|
| 26 | 26 | throw new InvalidArgumentException("$dir must be a directory"); |
| 27 | 27 | } |
| 28 | 28 | if (substr($dir, strlen($dir) - 1, 1) != '/') { |
| 29 | 29 | $dir .= '/'; |
| 30 | 30 | } |
| 31 | - $files = glob($dir . '*', GLOB_MARK); |
|
| 31 | + $files = glob($dir.'*', GLOB_MARK); |
|
| 32 | 32 | foreach ($files as $file) { |
| 33 | 33 | if (is_dir($file)) { |
| 34 | 34 | $this->removeDir($file); |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | $this->line("Cleaning code directory ..."); |
| 50 | 50 | |
| 51 | 51 | foreach ([base_path('laragen/app'), base_path('laragen/database')] as $dir) { |
| 52 | - if(file_exists($dir)){ |
|
| 52 | + if (file_exists($dir)) { |
|
| 53 | 53 | $fileSystem->removeDir($dir); |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -7,12 +7,12 @@ |
||
| 7 | 7 | class Api extends BaseGenerator implements GeneratorInterface |
| 8 | 8 | { |
| 9 | 9 | protected $destination = "laragen/app/Http/Controllers/Backend/Api"; |
| 10 | - protected $namespace = "Laragen\App\Http\Controllers\Backend\Api"; |
|
| 11 | - protected $template = "backend/Api"; |
|
| 10 | + protected $namespace = "Laragen\App\Http\Controllers\Backend\Api"; |
|
| 11 | + protected $template = "backend/Api"; |
|
| 12 | 12 | protected $fileSuffix = "ApiController"; |
| 13 | 13 | |
| 14 | 14 | protected $childDestination = "app/Http/Controllers/Backend/Api"; |
| 15 | - protected $childNamespace = "App\Http\Controllers\Backend\Api"; |
|
| 15 | + protected $childNamespace = "App\Http\Controllers\Backend\Api"; |
|
| 16 | 16 | |
| 17 | 17 | public function generate() |
| 18 | 18 | { |
@@ -7,12 +7,12 @@ |
||
| 7 | 7 | class Controller extends BaseGenerator implements GeneratorInterface |
| 8 | 8 | { |
| 9 | 9 | protected $destination = "laragen/app/Http/Controllers/Backend"; |
| 10 | - protected $namespace = "Laragen\App\Http\Controllers\Backend"; |
|
| 11 | - protected $template = "backend/Controller"; |
|
| 10 | + protected $namespace = "Laragen\App\Http\Controllers\Backend"; |
|
| 11 | + protected $template = "backend/Controller"; |
|
| 12 | 12 | protected $fileSuffix = "Controller"; |
| 13 | 13 | |
| 14 | 14 | protected $childDestination = "app/Http/Controllers/Backend"; |
| 15 | - protected $childNamespace = "App\Http\Controllers\Backend"; |
|
| 15 | + protected $childNamespace = "App\Http\Controllers\Backend"; |
|
| 16 | 16 | |
| 17 | 17 | public function generate() |
| 18 | 18 | { |
@@ -7,12 +7,12 @@ |
||
| 7 | 7 | class Request extends BaseGenerator implements GeneratorInterface |
| 8 | 8 | { |
| 9 | 9 | protected $destination = "laragen/app/Http/Requests/Backend"; |
| 10 | - protected $namespace = "Laragen\App\Http\Requests\Backend"; |
|
| 11 | - protected $template = "backend/Request"; |
|
| 10 | + protected $namespace = "Laragen\App\Http\Requests\Backend"; |
|
| 11 | + protected $template = "backend/Request"; |
|
| 12 | 12 | protected $fileSuffix = "Request"; |
| 13 | 13 | |
| 14 | 14 | protected $childDestination = "app/Http/Requests/Backend"; |
| 15 | - protected $childNamespace = "App\Http\Requests\Backend"; |
|
| 15 | + protected $childNamespace = "App\Http\Requests\Backend"; |
|
| 16 | 16 | |
| 17 | 17 | public function generate() |
| 18 | 18 | { |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @var string |
| 47 | 47 | */ |
| 48 | - protected $childTemplate = "backend/EmptyClass"; |
|
| 48 | + protected $childTemplate = "backend/EmptyClass"; |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * Option to check if generator requires a separate child class file to be generated |
@@ -84,12 +84,11 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function getStub($stubPath) |
| 86 | 86 | { |
| 87 | - $customThemeStub = base_path('laragen/stubs/' . $stubPath.".stub"); |
|
| 87 | + $customThemeStub = base_path('laragen/stubs/'.$stubPath.".stub"); |
|
| 88 | 88 | |
| 89 | 89 | // Set stub file to the one from custom folder i.e. laragen/stubs if it exists, else use default from laragen package |
| 90 | 90 | $stubFilePath = file_exists($customThemeStub) ? |
| 91 | - base_path('laragen/stubs/' . $stubPath.".stub") : |
|
| 92 | - realpath(__DIR__."/../stubs"). "/$stubPath.stub"; |
|
| 91 | + base_path('laragen/stubs/'.$stubPath.".stub") : realpath(__DIR__."/../stubs")."/$stubPath.stub"; |
|
| 93 | 92 | |
| 94 | 93 | return $this->getFileContents($stubFilePath); |
| 95 | 94 | } |
@@ -112,7 +111,7 @@ discard block |
||
| 112 | 111 | * @param string $filePath absolute path of file to be read |
| 113 | 112 | * @return string contents of the file |
| 114 | 113 | */ |
| 115 | - public function getFileContents($filePath){ |
|
| 114 | + public function getFileContents($filePath) { |
|
| 116 | 115 | return $this->sanitize(file_get_contents($filePath)); |
| 117 | 116 | } |
| 118 | 117 | |
@@ -142,7 +141,7 @@ discard block |
||
| 142 | 141 | */ |
| 143 | 142 | public function getFilePath($fileName = null) |
| 144 | 143 | { |
| 145 | - return $this->getPath($this->destination."/") . ($fileName ?? $this->module->getModelName()) . $this->fileSuffix . "." . $this->fileExtension; |
|
| 144 | + return $this->getPath($this->destination."/").($fileName ?? $this->module->getModelName()).$this->fileSuffix.".".$this->fileExtension; |
|
| 146 | 145 | } |
| 147 | 146 | |
| 148 | 147 | /** |
@@ -155,7 +154,7 @@ discard block |
||
| 155 | 154 | */ |
| 156 | 155 | public function getChildClassFilePath($fileName = null) |
| 157 | 156 | { |
| 158 | - return $this->getPath($this->childDestination."/") . ($fileName ?? $this->module->getModelName()) . $this->fileSuffix . "." . $this->fileExtension; |
|
| 157 | + return $this->getPath($this->childDestination."/").($fileName ?? $this->module->getModelName()).$this->fileSuffix.".".$this->fileExtension; |
|
| 159 | 158 | } |
| 160 | 159 | |
| 161 | 160 | /** |
@@ -171,13 +170,13 @@ discard block |
||
| 171 | 170 | $this->fileSystem->dumpFile($file, $content); |
| 172 | 171 | |
| 173 | 172 | // Check if a child should be generated as in regular laravel file structure |
| 174 | - if($this->needsChildGeneration()){ |
|
| 173 | + if ($this->needsChildGeneration()) { |
|
| 175 | 174 | $childFile = $this->getChildClassFilePath($filename); |
| 176 | - if(!file_exists($childFile)){ |
|
| 175 | + if (!file_exists($childFile)) { |
|
| 177 | 176 | $childFileContent = $this->buildTemplate($this->childTemplate, [ |
| 178 | 177 | '{{namespace}}' => $this->childNamespace, |
| 179 | - '{{className}}' => $filename ?? $this->module->getModelName() . $this->fileSuffix, |
|
| 180 | - '{{extendsClass}}' => $this->namespace . '\\' . ($filename ?? $this->module->getModelName() . $this->fileSuffix) |
|
| 178 | + '{{className}}' => $filename ?? $this->module->getModelName().$this->fileSuffix, |
|
| 179 | + '{{extendsClass}}' => $this->namespace.'\\'.($filename ?? $this->module->getModelName().$this->fileSuffix) |
|
| 181 | 180 | ]); |
| 182 | 181 | $this->fileSystem->dumpFile($childFile, $childFileContent); |
| 183 | 182 | } |
@@ -193,7 +192,7 @@ discard block |
||
| 193 | 192 | * |
| 194 | 193 | * @return boolean value of the property |
| 195 | 194 | */ |
| 196 | - public function needsChildGeneration(){ |
|
| 195 | + public function needsChildGeneration() { |
|
| 197 | 196 | return $this->needsChildGeneration; |
| 198 | 197 | } |
| 199 | 198 | |
@@ -205,16 +204,16 @@ discard block |
||
| 205 | 204 | * @return void |
| 206 | 205 | */ |
| 207 | 206 | public function deleteFiles($target) { |
| 208 | - if(is_dir($target)){ |
|
| 209 | - $files = glob( $target . '*', GLOB_MARK ); |
|
| 207 | + if (is_dir($target)) { |
|
| 208 | + $files = glob($target.'*', GLOB_MARK); |
|
| 210 | 209 | |
| 211 | - foreach( $files as $file ){ |
|
| 212 | - $this->deleteFiles( $file ); |
|
| 210 | + foreach ($files as $file) { |
|
| 211 | + $this->deleteFiles($file); |
|
| 213 | 212 | } |
| 214 | 213 | |
| 215 | - rmdir( $target ); |
|
| 216 | - } elseif(is_file($target)) { |
|
| 217 | - unlink( $target ); |
|
| 214 | + rmdir($target); |
|
| 215 | + } elseif (is_file($target)) { |
|
| 216 | + unlink($target); |
|
| 218 | 217 | } |
| 219 | 218 | } |
| 220 | 219 | |