@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | { |
| 51 | 51 | if ($this->hasSpecialSchema()) { |
| 52 | 52 | $schema = $this->processSpecialSchema(); |
| 53 | - }else{ |
|
| 53 | + } else { |
|
| 54 | 54 | foreach ($this->optionArray as $option) { |
| 55 | 55 | if ($option == self::COLUMN_UNIQUE) $this->hasUnique(); |
| 56 | - if (is_numeric($option) && $option <= 2048) $this->hasSize((int)$option); |
|
| 56 | + if (is_numeric($option) && $option <= 2048) $this->hasSize((int) $option); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $schema = '$table->' . $this->getType() . "('{$this->column}'"; |
|
| 59 | + $schema = '$table->'.$this->getType()."('{$this->column}'"; |
|
| 60 | 60 | $schema .= $this->hasSize() ? ", {$this->getSize()})" : ")"; |
| 61 | 61 | $schema .= $this->isUnique() ? "->unique()" : ""; |
| 62 | 62 | $schema .= ";"; |
@@ -64,23 +64,23 @@ discard block |
||
| 64 | 64 | return $schema; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - protected function getType(){ |
|
| 67 | + protected function getType() { |
|
| 68 | 68 | return $this->keyToType[array_shift($this->optionArray)]; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - protected function getSize(){ |
|
| 71 | + protected function getSize() { |
|
| 72 | 72 | return $this->size; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - protected function isUnique(){ |
|
| 75 | + protected function isUnique() { |
|
| 76 | 76 | return $this->uniqueFlag; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - protected function hasUnique($set = true){ |
|
| 79 | + protected function hasUnique($set = true) { |
|
| 80 | 80 | $this->uniqueFlag = ($set === true) ? true : false; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - protected function hasSize($size = null){ |
|
| 83 | + protected function hasSize($size = null) { |
|
| 84 | 84 | if ($size !== null) { |
| 85 | 85 | $this->size = $size; |
| 86 | 86 | } |
@@ -90,31 +90,31 @@ discard block |
||
| 90 | 90 | public function getTabs($number) |
| 91 | 91 | { |
| 92 | 92 | $schema = ""; |
| 93 | - for ($i=0; $i < $number; $i++) { |
|
| 93 | + for ($i = 0; $i < $number; $i++) { |
|
| 94 | 94 | $schema .= " "; |
| 95 | 95 | } |
| 96 | 96 | return $schema; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - protected function processSpecialSchema(){ |
|
| 100 | - $specialMethod = 'process' . ucfirst($this->specialType); |
|
| 99 | + protected function processSpecialSchema() { |
|
| 100 | + $specialMethod = 'process'.ucfirst($this->specialType); |
|
| 101 | 101 | return $this->$specialMethod(); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | - protected function processParent(){ |
|
| 104 | + protected function processParent() { |
|
| 105 | 105 | $schema = ""; |
| 106 | 106 | $parent = array_pop($this->optionArray); |
| 107 | - $schema .= "\$table->integer('" . str_singular($parent) . "_id')->unsigned()->nullable();"; |
|
| 108 | - $schema .= PHP_EOL . $this->getTabs(3); |
|
| 109 | - $schema .= "\$table->foreign('" . str_singular($parent) . "_id')->references('id')->on('$parent')->onDelete('set null');"; |
|
| 107 | + $schema .= "\$table->integer('".str_singular($parent)."_id')->unsigned()->nullable();"; |
|
| 108 | + $schema .= PHP_EOL.$this->getTabs(3); |
|
| 109 | + $schema .= "\$table->foreign('".str_singular($parent)."_id')->references('id')->on('$parent')->onDelete('set null');"; |
|
| 110 | 110 | return $schema; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - protected function processRelated(){ |
|
| 113 | + protected function processRelated() { |
|
| 114 | 114 | return ""; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - protected function hasSpecialSchema(){ |
|
| 117 | + protected function hasSpecialSchema() { |
|
| 118 | 118 | if ($this->optionArray[0] == self::TYPE_PARENT) { |
| 119 | 119 | array_shift($this->optionArray); |
| 120 | 120 | $this->specialType = self::TYPE_PARENT; |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | public function boot() |
| 14 | 14 | { |
| 15 | 15 | $this->publishes([ |
| 16 | - __DIR__ . '/../config/laragen.php' => config_path('laragen.php') |
|
| 16 | + __DIR__.'/../config/laragen.php' => config_path('laragen.php') |
|
| 17 | 17 | ], 'config'); |
| 18 | 18 | |
| 19 | 19 | Artisan::call('vendor:publish', [ |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | public function register() |
| 27 | 27 | { |
| 28 | 28 | $this->mergeConfigFrom( |
| 29 | - __DIR__ . '/../config/laragen.php', |
|
| 29 | + __DIR__.'/../config/laragen.php', |
|
| 30 | 30 | 'laragen' |
| 31 | 31 | ); |
| 32 | 32 | |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | public function getStub($type) |
| 26 | 26 | { |
| 27 | - return file_get_contents(__DIR__ . "/../resources/stubs/" . $type . ".stub"); |
|
| 27 | + return file_get_contents(__DIR__."/../resources/stubs/".$type.".stub"); |
|
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function getPath($path) |
| 31 | 31 | { |
| 32 | 32 | $dir = base_path($path); |
| 33 | 33 | |
| 34 | - if(!is_dir($dir)) |
|
| 34 | + if (!is_dir($dir)) |
|
| 35 | 35 | mkdir($dir, 0755, true); |
| 36 | 36 | |
| 37 | 37 | return $dir; |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | public function getTabs($number) |
| 46 | 46 | { |
| 47 | 47 | $schema = ""; |
| 48 | - for ($i=0; $i < $number; $i++) { |
|
| 48 | + for ($i = 0; $i < $number; $i++) { |
|
| 49 | 49 | $schema .= " "; |
| 50 | 50 | } |
| 51 | 51 | return $schema; |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $itemGenerator = new $generator($module); |
| 48 | 48 | $returnedFiles = $itemGenerator->generate(); |
| 49 | 49 | |
| 50 | - if(!is_array($returnedFiles)) |
|
| 50 | + if (!is_array($returnedFiles)) |
|
| 51 | 51 | $generatedFiles[] = $returnedFiles; |
| 52 | 52 | else |
| 53 | 53 | $generatedFiles = array_merge($generatedFiles, $returnedFiles); |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | $this->line("\n"); |
| 62 | 62 | |
| 63 | 63 | foreach ($generatedFiles as $file) { |
| 64 | - $this->info("Generated file: " . str_replace(base_path() . "\\", "", $file)); |
|
| 64 | + $this->info("Generated file: ".str_replace(base_path()."\\", "", $file)); |
|
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -18,9 +18,9 @@ discard block |
||
| 18 | 18 | '{{modelTableSchema}}' => $this->getSchema() |
| 19 | 19 | ]); |
| 20 | 20 | |
| 21 | - $fileCounter = (int)date('His') + ++self::$counter; |
|
| 22 | - $filenamePrefix = date('Y_m_d_') . $fileCounter . "_"; |
|
| 23 | - $fileName = "create_" . $this->module->getModuleName() . "_table.php"; |
|
| 21 | + $fileCounter = (int) date('His') + ++self::$counter; |
|
| 22 | + $filenamePrefix = date('Y_m_d_').$fileCounter."_"; |
|
| 23 | + $fileName = "create_".$this->module->getModuleName()."_table.php"; |
|
| 24 | 24 | |
| 25 | 25 | $existingFiles = scandir(database_path("migrations")); |
| 26 | 26 | |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $fullFilePath = database_path("migrations\\") . $filenamePrefix . $fileName; |
|
| 33 | + $fullFilePath = database_path("migrations\\").$filenamePrefix.$fileName; |
|
| 34 | 34 | file_put_contents($fullFilePath, $migrationTemplate); |
| 35 | 35 | |
| 36 | 36 | return $fullFilePath; |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $schema .= $option->getSchema(); |
| 49 | 49 | |
| 50 | 50 | if ($column != $lastColumn) { |
| 51 | - $schema .= PHP_EOL . $this->getTabs(3); |
|
| 51 | + $schema .= PHP_EOL.$this->getTabs(3); |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
@@ -14,14 +14,14 @@ |
||
| 14 | 14 | '{{foreignMethods}}' => $this->getForeignMethods() |
| 15 | 15 | ]); |
| 16 | 16 | |
| 17 | - $fullFilePath = $this->getPath("app/Models/") . $this->module->getModelName() . ".php"; |
|
| 17 | + $fullFilePath = $this->getPath("app/Models/").$this->module->getModelName().".php"; |
|
| 18 | 18 | file_put_contents($fullFilePath, $modelTemplate); |
| 19 | 19 | return $fullFilePath; |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | protected function getMassAssignables() |
| 23 | 23 | { |
| 24 | - return "'" . implode("', '", $this->module->getNativeColumns()) . "'"; |
|
| 24 | + return "'".implode("', '", $this->module->getNativeColumns())."'"; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | protected function getForeignMethods() |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | '{{modelNameSingularLowerCase}}' => strtolower($this->module->getModelName()) |
| 14 | 14 | ]); |
| 15 | 15 | |
| 16 | - $fullFilePath = $this->getPath("app/Http/Controllers/") . $this->module->getModelName() . "Controller" . ".php"; |
|
| 16 | + $fullFilePath = $this->getPath("app/Http/Controllers/").$this->module->getModelName()."Controller".".php"; |
|
| 17 | 17 | file_put_contents($fullFilePath, $controllerTemplate); |
| 18 | 18 | return $fullFilePath; |
| 19 | 19 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | public function __construct($module) |
| 16 | 16 | { |
| 17 | - $this->module = (object)$module; |
|
| 17 | + $this->module = (object) $module; |
|
| 18 | 18 | $this->data = $this->module->data; |
| 19 | 19 | $this->name = $this->module->name; |
| 20 | 20 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function getForeignColumns($type = 'all') |
| 57 | 57 | { |
| 58 | - if(is_array($type)) |
|
| 58 | + if (is_array($type)) |
|
| 59 | 59 | $types = $type; |
| 60 | 60 | else |
| 61 | 61 | $types = ($type == "all") ? ['parent', 'related'] : [$type]; |
@@ -15,37 +15,37 @@ discard block |
||
| 15 | 15 | '{{dataDefinition}}' => $this->getDataDefinition(), |
| 16 | 16 | '{{foreignData}}' => $this->getForeignData() |
| 17 | 17 | ]); |
| 18 | - $fullFilePath = $this->getPath("database/factories/") . $this->module->getModelName() . "Factory.php"; |
|
| 18 | + $fullFilePath = $this->getPath("database/factories/").$this->module->getModelName()."Factory.php"; |
|
| 19 | 19 | file_put_contents($fullFilePath, $modelTemplate); |
| 20 | - $generatedFiles[] = $fullFilePath; |
|
| 20 | + $generatedFiles[] = $fullFilePath; |
|
| 21 | 21 | |
| 22 | 22 | $modelTemplate = $this->buildTemplate('Seeder', [ |
| 23 | 23 | '{{modelName}}' => $this->module->getModelName(), |
| 24 | 24 | '{{usedModels}}' => $this->getUsedModels() |
| 25 | 25 | ]); |
| 26 | - $fullFilePath = $this->getPath("database/seeds/") . $this->module->getModelName() . "Seeder.php"; |
|
| 26 | + $fullFilePath = $this->getPath("database/seeds/").$this->module->getModelName()."Seeder.php"; |
|
| 27 | 27 | file_put_contents($fullFilePath, $modelTemplate); |
| 28 | - $generatedFiles[] = $fullFilePath; |
|
| 28 | + $generatedFiles[] = $fullFilePath; |
|
| 29 | 29 | |
| 30 | 30 | return $generatedFiles; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - protected function getUsedModels(){ |
|
| 33 | + protected function getUsedModels() { |
|
| 34 | 34 | $foreignModels = $this->module->getForeignColumns(); |
| 35 | 35 | $namespace = "App\\Models\\"; |
| 36 | - $usedModels = "use " . $namespace . $this->module->getModelName() . ";"; |
|
| 36 | + $usedModels = "use ".$namespace.$this->module->getModelName().";"; |
|
| 37 | 37 | |
| 38 | 38 | foreach ($foreignModels as $models) { |
| 39 | - foreach($models as $column => $module){ |
|
| 39 | + foreach ($models as $column => $module) { |
|
| 40 | 40 | $namespace = ($module == 'users' && class_exists('App\\User')) ? "App\\" : "App\\Models\\"; |
| 41 | - $class = $namespace . $this->moduleToModelName($module); |
|
| 42 | - $usedModels .= PHP_EOL . "use " . $class . ";"; |
|
| 41 | + $class = $namespace.$this->moduleToModelName($module); |
|
| 42 | + $usedModels .= PHP_EOL."use ".$class.";"; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | return $usedModels; |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - protected function getDataDefinition(){ |
|
| 48 | + protected function getDataDefinition() { |
|
| 49 | 49 | $specialTypesToDefinition = [ |
| 50 | 50 | 'title' => 'realText(50)', |
| 51 | 51 | 'firstname' => 'firstname', |
@@ -80,22 +80,22 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | $dataDefinition = ""; |
| 82 | 82 | foreach ($this->module->getNativeData() as $columns) { |
| 83 | - foreach($columns as $column => $type){ |
|
| 83 | + foreach ($columns as $column => $type) { |
|
| 84 | 84 | $specialTypes = array_keys($specialTypesToDefinition); |
| 85 | - if(in_array($column,$specialTypes)){ |
|
| 86 | - $dataDefinition .= $this->getTabs(2) . "'{$column}'" . " => " . '$faker->' . $specialTypesToDefinition[$column]; |
|
| 87 | - }else{ |
|
| 88 | - $dataDefinition .= $this->getTabs(2) . "'{$column}'" . " => " . '$faker->' . $typeToDefinition[$type]; |
|
| 85 | + if (in_array($column, $specialTypes)) { |
|
| 86 | + $dataDefinition .= $this->getTabs(2)."'{$column}'"." => ".'$faker->'.$specialTypesToDefinition[$column]; |
|
| 87 | + } else { |
|
| 88 | + $dataDefinition .= $this->getTabs(2)."'{$column}'"." => ".'$faker->'.$typeToDefinition[$type]; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if($column != last($columns)) |
|
| 92 | - $dataDefinition .= "," . PHP_EOL; |
|
| 91 | + if ($column != last($columns)) |
|
| 92 | + $dataDefinition .= ",".PHP_EOL; |
|
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | return $dataDefinition; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - protected function getForeignData(){ |
|
| 98 | + protected function getForeignData() { |
|
| 99 | 99 | $columns = $this->module->getForeignColumns('parent'); |
| 100 | 100 | |
| 101 | 101 | $foreignData = ""; |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | '{{parentModel}}' => ucfirst(camel_case(str_singular($parent))) |
| 108 | 108 | ]); |
| 109 | 109 | |
| 110 | - if($column != last($columns)) |
|
| 111 | - $foreignData .= "," . PHP_EOL; |
|
| 110 | + if ($column != last($columns)) |
|
| 111 | + $foreignData .= ",".PHP_EOL; |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |