@@ -4,10 +4,10 @@ |
||
| 4 | 4 | use Illuminate\Support\Str; |
| 5 | 5 | use Prateekkarki\Laragen\Models\TypeResolver; |
| 6 | 6 | |
| 7 | - /** |
|
| 8 | - * @method integer getSize() |
|
| 9 | - * @method array getPivotColumns() |
|
| 10 | - */ |
|
| 7 | + /** |
|
| 8 | + * @method integer getSize() |
|
| 9 | + * @method array getPivotColumns() |
|
| 10 | + */ |
|
| 11 | 11 | abstract class LaragenType |
| 12 | 12 | { |
| 13 | 13 | protected $uniqueFlag; |
@@ -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 | 178 | '{{className}}' => $this->module->getModelName(), |
| 180 | - '{{extendsClass}}' => $this->namespace . '\\' . $this->module->getModelName() |
|
| 179 | + '{{extendsClass}}' => $this->namespace.'\\'.$this->module->getModelName() |
|
| 181 | 180 | ]); |
| 182 | 181 | $this->fileSystem->dumpFile($childFile, $childFileContent); |
| 183 | 182 | } |
@@ -193,7 +192,7 @@ discard block |
||
| 193 | 192 | * |
| 194 | 193 | * @return boolean |
| 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 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | protected function updateSeeder() { |
| 160 | 160 | $laragenSeederFile = $this->getPath("database/seeds/")."LaragenSeeder.php"; |
| 161 | 161 | |
| 162 | - if(self::$initializeFlag++ == 0) |
|
| 162 | + if (self::$initializeFlag++ == 0) |
|
| 163 | 163 | $this->initializeFile($laragenSeederFile, 'common/Seeder'); |
| 164 | 164 | |
| 165 | 165 | $this->insertIntoFile( |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | $this->insertIntoFile( |
| 214 | 214 | $laragenSeederFile, |
| 215 | 215 | "\n // End factories", |
| 216 | - "\n".$this->getTabs(2)."factory(".$type->getPivot()."::class, " . ((int) config('laragen.options.seed_rows') * 2) . ")->create();", |
|
| 216 | + "\n".$this->getTabs(2)."factory(".$type->getPivot()."::class, ".((int) config('laragen.options.seed_rows') * 2).")->create();", |
|
| 217 | 217 | false |
| 218 | 218 | ); |
| 219 | 219 | } |
@@ -146,7 +146,9 @@ discard block |
||
| 146 | 146 | $foreignData = ""; |
| 147 | 147 | |
| 148 | 148 | foreach ($types as $type) { |
| 149 | - if ($type->hasSelfParent()) continue; |
|
| 149 | + if ($type->hasSelfParent()) { |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 150 | 152 | $foreignData .= $this->buildTemplate('common/Factories/fragments/options', [ |
| 151 | 153 | '{{parent}}' => $type->getColumnKey(), |
| 152 | 154 | '{{parentModel}}' => $type->getRelatedModel() |
@@ -159,8 +161,9 @@ discard block |
||
| 159 | 161 | protected function updateSeeder() { |
| 160 | 162 | $laragenSeederFile = $this->getPath("database/seeds/")."LaragenSeeder.php"; |
| 161 | 163 | |
| 162 | - if(self::$initializeFlag++ == 0) |
|
| 163 | - $this->initializeFile($laragenSeederFile, 'common/Seeder'); |
|
| 164 | + if(self::$initializeFlag++ == 0) { |
|
| 165 | + $this->initializeFile($laragenSeederFile, 'common/Seeder'); |
|
| 166 | + } |
|
| 164 | 167 | |
| 165 | 168 | $this->insertIntoFile( |
| 166 | 169 | $laragenSeederFile, |