@@ -11,6 +11,6 @@ |
||
| 11 | 11 | | |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -$router->get("/", function () use ($router) { |
|
| 14 | +$router->get("/", function() use ($router) { |
|
| 15 | 15 | return 'Hello World'; |
| 16 | 16 | }); |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require_once __DIR__.'/../vendor/autoload.php'; |
|
| 3 | +require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 4 | 4 | |
| 5 | 5 | try { |
| 6 | - (new Dotenv\Dotenv(__DIR__.'/../'))->load(); |
|
| 6 | + (new Dotenv\Dotenv(__DIR__ . '/../'))->load(); |
|
| 7 | 7 | } catch (Dotenv\Exception\InvalidPathException $e) { |
| 8 | 8 | // |
| 9 | 9 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | $app = new Laravel\Lumen\Application( |
| 23 | - realpath(__DIR__.'/../') |
|
| 23 | + realpath(__DIR__ . '/../') |
|
| 24 | 24 | ); |
| 25 | 25 | |
| 26 | 26 | $app->withFacades(); |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | |
| 99 | 99 | $app->router->group([ |
| 100 | 100 | 'namespace' => 'App\Http\Controllers', |
| 101 | -], function ($router) { |
|
| 102 | - require __DIR__.'/../app/Http/routes.php'; |
|
| 101 | +], function($router) { |
|
| 102 | + require __DIR__ . '/../app/Http/routes.php'; |
|
| 103 | 103 | }); |
| 104 | 104 | |
| 105 | 105 | return $app; |
@@ -14,10 +14,10 @@ discard block |
||
| 14 | 14 | $I->seeInThisFile('protected $fillable = ["name", "descr", "due", "project_id", "creator_id"];'); |
| 15 | 15 | $I->seeInThisFile('protected $dates = ["due"];'); |
| 16 | 16 | $I->seeInThisFile( |
| 17 | -"public static \$rules = [\n". |
|
| 17 | +"public static \$rules = [\n" . |
|
| 18 | 18 | " \"name\" => \"requied\"," . PHP_EOL . |
| 19 | 19 | " \"project_id\" => \"required|numeric\"," . PHP_EOL . |
| 20 | -" \"creator_id\" => \"required|numeric\",\n". |
|
| 20 | +" \"creator_id\" => \"required|numeric\",\n" . |
|
| 21 | 21 | " ];"); |
| 22 | 22 | $I->seeInThisFile( |
| 23 | 23 | ' public function tags() |
@@ -47,19 +47,19 @@ discard block |
||
| 47 | 47 | $I->openFile('./database/migrations/create_task_categories.php'); |
| 48 | 48 | |
| 49 | 49 | $I->seeInThisFile('class CreateTaskCategoriesTable extends Migration'); |
| 50 | -$I->seeInThisFile("Schema::create('task_categories', function(Blueprint \$table) {\n". |
|
| 51 | -" \$table->increments('id');\n". |
|
| 50 | +$I->seeInThisFile("Schema::create('task_categories', function(Blueprint \$table) {\n" . |
|
| 51 | +" \$table->increments('id');\n" . |
|
| 52 | 52 | " \$table->string('name')->unique();" . PHP_EOL . |
| 53 | 53 | " \$table->text('descr')->nullable();" . PHP_EOL . |
| 54 | 54 | " \$table->timestamp('due');" . PHP_EOL . |
| 55 | -" \$table->integer('project_id')->unsigned();" . PHP_EOL. |
|
| 55 | +" \$table->integer('project_id')->unsigned();" . PHP_EOL . |
|
| 56 | 56 | " \$table->integer('creator_id')->unsigned();\n" . |
| 57 | -" \$table->foreign('project_id')\n". |
|
| 58 | -" ->references('id')\n". |
|
| 57 | +" \$table->foreign('project_id')\n" . |
|
| 58 | +" ->references('id')\n" . |
|
| 59 | 59 | " ->on('projects');" . PHP_EOL . |
| 60 | -" \$table->foreign('creator_id')\n". |
|
| 61 | -" ->references('id')\n". |
|
| 62 | -" ->on('users');\n". |
|
| 60 | +" \$table->foreign('creator_id')\n" . |
|
| 61 | +" ->references('id')\n" . |
|
| 62 | +" ->on('users');\n" . |
|
| 63 | 63 | " \$table->timestamps();"); |
| 64 | 64 | |
| 65 | 65 | $I->deleteFile('./database/migrations/create_task_categories.php'); |
@@ -22,92 +22,92 @@ |
||
| 22 | 22 | // registerTestCommand |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - protected function registerModelCommand(){ |
|
| 26 | - $this->app->singleton('command.wn.model', function($app){ |
|
| 25 | + protected function registerModelCommand() { |
|
| 26 | + $this->app->singleton('command.wn.model', function($app) { |
|
| 27 | 27 | return $app['Wn\Generators\Commands\ModelCommand']; |
| 28 | 28 | }); |
| 29 | 29 | $this->commands('command.wn.model'); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - protected function registerControllerRestActionsCommand(){ |
|
| 33 | - $this->app->singleton('command.wn.controller.rest-actions', function($app){ |
|
| 32 | + protected function registerControllerRestActionsCommand() { |
|
| 33 | + $this->app->singleton('command.wn.controller.rest-actions', function($app) { |
|
| 34 | 34 | return $app['Wn\Generators\Commands\ControllerRestActionsCommand']; |
| 35 | 35 | }); |
| 36 | 36 | $this->commands('command.wn.controller.rest-actions'); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - protected function registerControllerCommand(){ |
|
| 40 | - $this->app->singleton('command.wn.controller', function($app){ |
|
| 39 | + protected function registerControllerCommand() { |
|
| 40 | + $this->app->singleton('command.wn.controller', function($app) { |
|
| 41 | 41 | return $app['Wn\Generators\Commands\ControllerCommand']; |
| 42 | 42 | }); |
| 43 | 43 | $this->commands('command.wn.controller'); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - protected function registerMigrationCommand(){ |
|
| 47 | - $this->app->singleton('command.wn.migration', function($app){ |
|
| 46 | + protected function registerMigrationCommand() { |
|
| 47 | + $this->app->singleton('command.wn.migration', function($app) { |
|
| 48 | 48 | return $app['Wn\Generators\Commands\MigrationCommand']; |
| 49 | 49 | }); |
| 50 | 50 | $this->commands('command.wn.migration'); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - protected function registerRouteCommand(){ |
|
| 54 | - $this->app->singleton('command.wn.route', function($app){ |
|
| 53 | + protected function registerRouteCommand() { |
|
| 54 | + $this->app->singleton('command.wn.route', function($app) { |
|
| 55 | 55 | return $app['Wn\Generators\Commands\RouteCommand']; |
| 56 | 56 | }); |
| 57 | 57 | $this->commands('command.wn.route'); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - protected function registerTestCommand(){ |
|
| 61 | - $this->app->singleton('command.wn.test', function($app){ |
|
| 60 | + protected function registerTestCommand() { |
|
| 61 | + $this->app->singleton('command.wn.test', function($app) { |
|
| 62 | 62 | return $app['Wn\Generators\Commands\TestCommand']; |
| 63 | 63 | }); |
| 64 | 64 | $this->commands('command.wn.test'); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - protected function registerResourceCommand(){ |
|
| 68 | - $this->app->singleton('command.wn.resource', function($app){ |
|
| 67 | + protected function registerResourceCommand() { |
|
| 68 | + $this->app->singleton('command.wn.resource', function($app) { |
|
| 69 | 69 | return $app['Wn\Generators\Commands\ResourceCommand']; |
| 70 | 70 | }); |
| 71 | 71 | $this->commands('command.wn.resource'); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - protected function registerResourcesCommand(){ |
|
| 75 | - $this->app->singleton('command.wn.resources', function($app){ |
|
| 74 | + protected function registerResourcesCommand() { |
|
| 75 | + $this->app->singleton('command.wn.resources', function($app) { |
|
| 76 | 76 | return $app['Wn\Generators\Commands\ResourcesCommand']; |
| 77 | 77 | }); |
| 78 | 78 | $this->commands('command.wn.resources'); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - protected function registerPivotTableCommand(){ |
|
| 82 | - $this->app->singleton('command.wn.pivot-table', function($app){ |
|
| 81 | + protected function registerPivotTableCommand() { |
|
| 82 | + $this->app->singleton('command.wn.pivot-table', function($app) { |
|
| 83 | 83 | return $app['Wn\Generators\Commands\PivotTableCommand']; |
| 84 | 84 | }); |
| 85 | 85 | $this->commands('command.wn.pivot-table'); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - protected function registerMorphTableCommand(){ |
|
| 89 | - $this->app->singleton('command.wn.morph-table', function($app){ |
|
| 88 | + protected function registerMorphTableCommand() { |
|
| 89 | + $this->app->singleton('command.wn.morph-table', function($app) { |
|
| 90 | 90 | return $app['Wn\Generators\Commands\MorphTableCommand']; |
| 91 | 91 | }); |
| 92 | 92 | $this->commands('command.wn.morph-table'); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - protected function registerFactoryCommand(){ |
|
| 96 | - $this->app->singleton('command.wn.factory', function($app){ |
|
| 95 | + protected function registerFactoryCommand() { |
|
| 96 | + $this->app->singleton('command.wn.factory', function($app) { |
|
| 97 | 97 | return $app['Wn\Generators\Commands\FactoryCommand']; |
| 98 | 98 | }); |
| 99 | 99 | $this->commands('command.wn.factory'); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - protected function registerSeederCommand(){ |
|
| 103 | - $this->app->singleton('command.wn.seeder', function($app){ |
|
| 102 | + protected function registerSeederCommand() { |
|
| 103 | + $this->app->singleton('command.wn.seeder', function($app) { |
|
| 104 | 104 | return $app['Wn\Generators\Commands\SeederCommand']; |
| 105 | 105 | }); |
| 106 | 106 | $this->commands('command.wn.seeder'); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - protected function registerPivotSeederCommand(){ |
|
| 110 | - $this->app->singleton('command.wn.pivot.seeder', function($app){ |
|
| 109 | + protected function registerPivotSeederCommand() { |
|
| 110 | + $this->app->singleton('command.wn.pivot.seeder', function($app) { |
|
| 111 | 111 | return $app['Wn\Generators\Commands\PivotSeederCommand']; |
| 112 | 112 | }); |
| 113 | 113 | $this->commands('command.wn.pivot.seeder'); |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | $snakeName = snake_case($name); |
| 25 | 25 | |
| 26 | 26 | $file = $this->option('file'); |
| 27 | - if(! $file){ |
|
| 28 | - $name = "Migration".sprintf('%06d', self::$COUNTER++) . $name; |
|
| 27 | + if (!$file) { |
|
| 28 | + $name = "Migration" . sprintf('%06d', self::$COUNTER++) . $name; |
|
| 29 | 29 | $file = date('Y_m_d_His_') . snake_case($name) . '_table'; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -40,10 +40,10 @@ discard block |
||
| 40 | 40 | ->get(); |
| 41 | 41 | |
| 42 | 42 | $file = $this->option('file'); |
| 43 | - if(! $file){ |
|
| 43 | + if (!$file) { |
|
| 44 | 44 | $file = date('Y_m_d_His_') . $snakeName . '_table'; |
| 45 | 45 | $this->deleteOldMigration($snakeName); |
| 46 | - }else{ |
|
| 46 | + } else { |
|
| 47 | 47 | $this->deleteOldMigration($file); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | protected function deleteOldMigration($fileName) |
| 54 | 54 | { |
| 55 | - foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){ |
|
| 56 | - if($fileInfo->isDot()) continue; |
|
| 55 | + foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo) { |
|
| 56 | + if ($fileInfo->isDot()) continue; |
|
| 57 | 57 | |
| 58 | - if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){ |
|
| 58 | + if (strpos($fileInfo->getFilename(), $fileName) !== FALSE) { |
|
| 59 | 59 | unlink($fileInfo->getPathname()); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -64,12 +64,12 @@ discard block |
||
| 64 | 64 | protected function getSchema() |
| 65 | 65 | { |
| 66 | 66 | $schema = $this->option('schema'); |
| 67 | - if(! $schema){ |
|
| 67 | + if (!$schema) { |
|
| 68 | 68 | return $this->spaces(12) . "// Schema declaration"; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $items = $schema; |
| 72 | - if( ! $this->option('parsed')){ |
|
| 72 | + if (!$this->option('parsed')) { |
|
| 73 | 73 | $items = $this->getArgumentParser('schema')->parse($schema); |
| 74 | 74 | } |
| 75 | 75 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $name = $parts[0]['name']; |
| 104 | 104 | $parts[1]['args'] = array_merge(["'{$name}'"], $parts[1]['args']); |
| 105 | 105 | unset($parts[0]); |
| 106 | - $parts = array_map(function($part){ |
|
| 106 | + $parts = array_map(function($part) { |
|
| 107 | 107 | return '->' . $part['name'] . '(' . implode(', ', $part['args']) . ')'; |
| 108 | 108 | }, $parts); |
| 109 | 109 | return " \$table" . implode('', $parts) . ';'; |
@@ -112,12 +112,12 @@ discard block |
||
| 112 | 112 | protected function getConstraints() |
| 113 | 113 | { |
| 114 | 114 | $keys = $this->option('keys'); |
| 115 | - if(! $keys){ |
|
| 115 | + if (!$keys) { |
|
| 116 | 116 | return $this->spaces(12) . "// Constraints declaration"; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $items = $keys; |
| 120 | - if(! $this->option('parsed')){ |
|
| 120 | + if (!$this->option('parsed')) { |
|
| 121 | 121 | $items = $this->getArgumentParser('foreign-keys')->parse($keys); |
| 122 | 122 | } |
| 123 | 123 | |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | protected function getConstraintDeclaration($key) |
| 133 | 133 | { |
| 134 | - if(! $key['column']){ |
|
| 134 | + if (!$key['column']) { |
|
| 135 | 135 | $key['column'] = 'id'; |
| 136 | 136 | } |
| 137 | - if(! $key['table']){ |
|
| 137 | + if (!$key['table']) { |
|
| 138 | 138 | $key['table'] = substr($key['name'], 0, count($key['name']) - 4); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | ]) |
| 147 | 147 | ->get(); |
| 148 | 148 | |
| 149 | - if($key['on_delete']){ |
|
| 149 | + if ($key['on_delete']) { |
|
| 150 | 150 | $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') |
| 151 | 151 | ->with([ |
| 152 | 152 | 'event' => 'Delete', |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | ->get(); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if($key['on_update']){ |
|
| 158 | + if ($key['on_update']) { |
|
| 159 | 159 | $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') |
| 160 | 160 | ->with([ |
| 161 | 161 | 'event' => 'Update', |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | $files = $this->argument('files'); |
| 37 | 37 | $this->nodes = []; |
| 38 | 38 | foreach ($files as $file) { |
| 39 | - $this->info("Reading file ".$file); |
|
| 39 | + $this->info("Reading file " . $file); |
|
| 40 | 40 | |
| 41 | 41 | $content = $this->fs->get($file); |
| 42 | 42 | $content = Yaml::parse($content); |
| 43 | 43 | |
| 44 | - foreach ($content as $model => $i){ |
|
| 44 | + foreach ($content as $model => $i) { |
|
| 45 | 45 | /* |
| 46 | 46 | $i['modelname'] = as originally in YAML defined |
| 47 | 47 | $i['name'] = as originally defined in snake_case |
@@ -54,12 +54,12 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | if (empty($this->nodes[$model]) || $this->option('force-redefine')) { |
| 56 | 56 | if (!empty($this->nodes[$model])) { |
| 57 | - $this->checkError($model . ": forced to redefine (in file " . $this->nodes[$model]['filename'] . ", redefined from file ".$file.")"); |
|
| 57 | + $this->checkError($model . ": forced to redefine (in file " . $this->nodes[$model]['filename'] . ", redefined from file " . $file . ")"); |
|
| 58 | 58 | } |
| 59 | 59 | $i = $this->getResourceParams($i); |
| 60 | 60 | $this->nodes[$model] = $i; |
| 61 | 61 | } else { |
| 62 | - $this->checkError($model . ": already defined (in file " . $this->nodes[$model]['filename'] . ", trying to redefine from file ".$file."; Use --force-redefine to force redefinition)"); |
|
| 62 | + $this->checkError($model . ": already defined (in file " . $this->nodes[$model]['filename'] . ", trying to redefine from file " . $file . "; Use --force-redefine to force redefinition)"); |
|
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $this->nodes = $this->sortDependencies(); |
| 71 | 71 | |
| 72 | - if (! $this->option('skip-check')) { |
|
| 72 | + if (!$this->option('skip-check')) { |
|
| 73 | 73 | $this->info('Checking Relationships...'); |
| 74 | 74 | $keys = array_keys($this->nodes); |
| 75 | 75 | foreach ($this->nodes as $model => $i) { |
@@ -88,17 +88,17 @@ discard block |
||
| 88 | 88 | $this->printErrors(); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
|
| 92 | - if (! $this->option('check-only') && $this->checkedErrors > 0) { |
|
| 91 | + $proceed = (!$this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
|
| 92 | + if (!$this->option('check-only') && $this->checkedErrors > 0) { |
|
| 93 | 93 | $this->line(''); |
| 94 | 94 | $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
| 95 | 95 | } |
| 96 | 96 | if ($proceed) { |
| 97 | 97 | $modelIndex = 0; |
| 98 | - $migrationIdLength = strlen((string)count($this->nodes)); |
|
| 98 | + $migrationIdLength = strlen((string) count($this->nodes)); |
|
| 99 | 99 | foreach ($this->nodes as $i) { |
| 100 | - $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
| 101 | - $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
| 100 | + $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
| 101 | + $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex, $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
| 102 | 102 | |
| 103 | 103 | $this->line(''); |
| 104 | 104 | $this->info('Building Model ' . $i['uniquename']); |
@@ -199,39 +199,39 @@ discard block |
||
| 199 | 199 | $i['modelname'] = $i['modelname']; |
| 200 | 200 | $i['uniquename'] = $i['uniquename']; |
| 201 | 201 | |
| 202 | - foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation){ |
|
| 203 | - if(isset($i[$relation])){ |
|
| 202 | + foreach (['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation) { |
|
| 203 | + if (isset($i[$relation])) { |
|
| 204 | 204 | $i[$relation] = $this->convertArray($i[$relation], ' ', ','); |
| 205 | 205 | } else { |
| 206 | 206 | $i[$relation] = false; |
| 207 | 207 | } |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if($i['belongsToMany']){ |
|
| 210 | + if ($i['belongsToMany']) { |
|
| 211 | 211 | $relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']); |
| 212 | - foreach ($relations as $relation){ |
|
| 212 | + foreach ($relations as $relation) { |
|
| 213 | 213 | $table = ''; |
| 214 | 214 | |
| 215 | - if(! $relation['model']){ |
|
| 215 | + if (!$relation['model']) { |
|
| 216 | 216 | $table = snake_case($relation['name']); |
| 217 | 217 | } else { |
| 218 | 218 | $names = array_reverse(explode("\\", $relation['model'])); |
| 219 | 219 | $table = snake_case($names[0]); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - $tables = [ str_singular($table), $i['name'] ]; |
|
| 222 | + $tables = [str_singular($table), $i['name']]; |
|
| 223 | 223 | sort($tables); |
| 224 | 224 | $tables[] = $modelName; |
| 225 | 225 | $this->pivotTables[] = $tables; |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | - if($i['morphToMany']){ |
|
| 229 | + if ($i['morphToMany']) { |
|
| 230 | 230 | $relations = $this->getArgumentParser('relations-morphMany')->parse($i['morphToMany']); |
| 231 | - foreach ($relations as $relation){ |
|
| 231 | + foreach ($relations as $relation) { |
|
| 232 | 232 | $table = ''; |
| 233 | 233 | |
| 234 | - if(! $relation['through']){ |
|
| 234 | + if (!$relation['through']) { |
|
| 235 | 235 | $names = array_reverse(explode("\\", $relation['model'])); |
| 236 | 236 | $morphable = snake_case($names[0]); |
| 237 | 237 | $model = snake_case($relation['name']); |
@@ -242,17 +242,17 @@ discard block |
||
| 242 | 242 | $model = snake_case($names[0]); |
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - $tables = [ str_singular($model), str_singular($morphable), $modelName ]; |
|
| 245 | + $tables = [str_singular($model), str_singular($morphable), $modelName]; |
|
| 246 | 246 | $this->morphTables[] = $tables; |
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - if($i['morphedByMany']){ |
|
| 250 | + if ($i['morphedByMany']) { |
|
| 251 | 251 | $relations = $this->getArgumentParser('relations-morphMany')->parse($i['morphedByMany']); |
| 252 | - foreach ($relations as $relation){ |
|
| 252 | + foreach ($relations as $relation) { |
|
| 253 | 253 | $table = ''; |
| 254 | 254 | |
| 255 | - if(! $relation['through']){ |
|
| 255 | + if (!$relation['through']) { |
|
| 256 | 256 | $names = array_reverse(explode("\\", $relation['model'])); |
| 257 | 257 | $morphable = snake_case($names[0]); |
| 258 | 258 | } else { |
@@ -260,13 +260,13 @@ discard block |
||
| 260 | 260 | $morphable = snake_case($names[0]); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | - $tables = [ str_singular($i['name']), str_singular($morphable), $modelName ]; |
|
| 263 | + $tables = [str_singular($i['name']), str_singular($morphable), $modelName]; |
|
| 264 | 264 | $this->morphTables[] = $tables; |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | $fields = []; |
| 269 | - foreach($i['fields'] as $name => $value) { |
|
| 269 | + foreach ($i['fields'] as $name => $value) { |
|
| 270 | 270 | $value['name'] = $name; |
| 271 | 271 | $fields[] = $this->serializeField($value); |
| 272 | 272 | } |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | |
| 285 | 285 | $string = "{$name};{$schema};{$rules};{$tags}"; |
| 286 | 286 | |
| 287 | - if(isset($field['factory']) && !empty($field['factory'])){ |
|
| 287 | + if (isset($field['factory']) && !empty($field['factory'])) { |
|
| 288 | 288 | $string .= ';' . $field['factory']; |
| 289 | 289 | } |
| 290 | 290 | |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | |
| 294 | 294 | protected function convertArray($list, $old, $new) |
| 295 | 295 | { |
| 296 | - return implode($new, array_filter(explode($old, $list), function($item){ |
|
| 296 | + return implode($new, array_filter(explode($old, $list), function($item) { |
|
| 297 | 297 | return !empty($item); |
| 298 | 298 | })); |
| 299 | 299 | } |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | $load_order = array(); |
| 303 | 303 | $seen = array(); |
| 304 | 304 | |
| 305 | - foreach($this->nodes as $key => $item) { |
|
| 305 | + foreach ($this->nodes as $key => $item) { |
|
| 306 | 306 | $tmp = $this->getDependencies($key, $seen); |
| 307 | 307 | |
| 308 | 308 | // if($tmp[2] === false) { |
@@ -315,22 +315,22 @@ discard block |
||
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | private function getDependencies($key, $seen = array()) { |
| 318 | - if(array_key_exists($key, $seen) == true) { |
|
| 318 | + if (array_key_exists($key, $seen) == true) { |
|
| 319 | 319 | return array(array(), $seen); |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
| 323 | - if(!empty($this->nodes[$key])) { |
|
| 323 | + if (!empty($this->nodes[$key])) { |
|
| 324 | 324 | $order = array(); |
| 325 | 325 | // $failed = array(); |
| 326 | 326 | |
| 327 | - if($this->nodes[$key]['belongsTo']) { |
|
| 327 | + if ($this->nodes[$key]['belongsTo']) { |
|
| 328 | 328 | $deps = $this->getArgumentParser('relations')->parse($this->nodes[$key]['belongsTo']); |
| 329 | - foreach($deps as $dependency) { |
|
| 330 | - if(! $dependency['model']){ |
|
| 329 | + foreach ($deps as $dependency) { |
|
| 330 | + if (!$dependency['model']) { |
|
| 331 | 331 | $dependency['model'] = $dependency['name']; |
| 332 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
| 333 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); |
|
| 332 | + } else if (strpos($dependency['model'], '\\') !== false) { |
|
| 333 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\') + 1); |
|
| 334 | 334 | } |
| 335 | 335 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
| 336 | 336 | if ($dependency['model'] != $key) { |
@@ -349,10 +349,10 @@ discard block |
||
| 349 | 349 | $order[$key] = $this->nodes[$key]; |
| 350 | 350 | // $failed = (count($failed) > 0) ? $failed : false; |
| 351 | 351 | |
| 352 | - return array($order, $seen);//, $failed |
|
| 352 | + return array($order, $seen); //, $failed |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | - return array(array(), $seen);//, array($item) |
|
| 355 | + return array(array(), $seen); //, array($item) |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | protected function checkError($message, $model = "", $file = "") { |
@@ -377,10 +377,10 @@ discard block |
||
| 377 | 377 | if ($relations) { |
| 378 | 378 | $position = array_search($model, $keys); |
| 379 | 379 | $relations = $this->getArgumentParser('relations')->parse($relations); |
| 380 | - foreach($relations as $relation) { |
|
| 381 | - switch($type) { |
|
| 380 | + foreach ($relations as $relation) { |
|
| 381 | + switch ($type) { |
|
| 382 | 382 | case "belongsTo": |
| 383 | - $rModel = $relation['model']?$relation['model']:$relation['name']; break; |
|
| 383 | + $rModel = $relation['model'] ? $relation['model'] : $relation['name']; break; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $search = array_search(studly_case(str_singular($rModel)), $keys); |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | |
| 398 | 398 | protected function checkPivotRelations($relations, $rType) { |
| 399 | 399 | if ($relations) { |
| 400 | - foreach($relations as $relation) { |
|
| 400 | + foreach ($relations as $relation) { |
|
| 401 | 401 | $relation['0'] = studly_case(str_singular($relation['0'])); |
| 402 | 402 | $relation['1'] = studly_case(str_singular($relation['1'])); |
| 403 | 403 | $relation['2'] = studly_case(str_singular($relation['2'])); |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | protected function getAsArrayFields($arg, $isOption = true) |
| 51 | 51 | { |
| 52 | 52 | $arg = ($isOption) ? $this->option($arg) : $this->argument($arg); |
| 53 | - if(is_string($arg)){ |
|
| 53 | + if (is_string($arg)) { |
|
| 54 | 54 | $arg = explode(',', $arg); |
| 55 | - } else if(! is_array($arg)) { |
|
| 55 | + } else if (!is_array($arg)) { |
|
| 56 | 56 | $arg = []; |
| 57 | 57 | } |
| 58 | - return implode(', ', array_map(function($item){ |
|
| 58 | + return implode(', ', array_map(function($item) { |
|
| 59 | 59 | return '"' . $item . '"'; |
| 60 | 60 | }, $arg)); |
| 61 | 61 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $this->getRelationsByType('morphedByMany', 'morphed-by-many', false, 'relations-morphMany') |
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | - if(empty($relations)){ |
|
| 77 | + if (empty($relations)) { |
|
| 78 | 78 | return " // Relationships"; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -85,38 +85,38 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | $relations = []; |
| 87 | 87 | $option = $this->option($option); |
| 88 | - if($option){ |
|
| 88 | + if ($option) { |
|
| 89 | 89 | |
| 90 | 90 | $items = $this->getArgumentParser($parser)->parse($option); |
| 91 | 91 | |
| 92 | - $template = ($withTimestamps) ? 'model/relation-with-timestamps' : ($parser=='relations'?'model/relation':'model/relation-'.$type); |
|
| 92 | + $template = ($withTimestamps) ? 'model/relation-with-timestamps' : ($parser == 'relations' ? 'model/relation' : 'model/relation-' . $type); |
|
| 93 | 93 | $template = $this->getTemplate($template); |
| 94 | 94 | foreach ($items as $item) { |
| 95 | 95 | $item['type'] = $type; |
| 96 | 96 | if ($parser == 'relations') { |
| 97 | - if(! $item['model']){ |
|
| 97 | + if (!$item['model']) { |
|
| 98 | 98 | $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['name'])); |
| 99 | - } else if(strpos($item['model'], '\\') === false ){ |
|
| 99 | + } else if (strpos($item['model'], '\\') === false) { |
|
| 100 | 100 | $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
| 101 | 101 | } |
| 102 | 102 | } else if ($parser != 'relations') { |
| 103 | - switch($type) { |
|
| 103 | + switch ($type) { |
|
| 104 | 104 | case "hasManyThrough": |
| 105 | - if(! $item['through'] && $item['model']){ |
|
| 105 | + if (!$item['through'] && $item['model']) { |
|
| 106 | 106 | $item['through'] = $item['model']; |
| 107 | 107 | $item['model'] = $item['name']; |
| 108 | 108 | |
| 109 | - if(strpos($item['through'], '\\') === false ){ |
|
| 109 | + if (strpos($item['through'], '\\') === false) { |
|
| 110 | 110 | $item['through'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['through'])); |
| 111 | 111 | } |
| 112 | - if(strpos($item['model'], '\\') === false ){ |
|
| 112 | + if (strpos($item['model'], '\\') === false) { |
|
| 113 | 113 | $item['model'] = $this->getNamespace() . '\\' . ucwords(str_singular($item['model'])); |
| 114 | 114 | } |
| 115 | 115 | } else { |
| 116 | - if(strpos($item['through'], '\\') === false ){ |
|
| 116 | + if (strpos($item['through'], '\\') === false) { |
|
| 117 | 117 | $item['through'] = $this->getNamespace() . '\\' . $item['through']; |
| 118 | 118 | } |
| 119 | - if(strpos($item['model'], '\\') === false ){ |
|
| 119 | + if (strpos($item['model'], '\\') === false) { |
|
| 120 | 120 | $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -124,11 +124,11 @@ discard block |
||
| 124 | 124 | case "morphMany": |
| 125 | 125 | case "morphToMany": |
| 126 | 126 | case "morphedByMany": |
| 127 | - if(! $item['through']){ |
|
| 127 | + if (!$item['through']) { |
|
| 128 | 128 | $item['through'] = $item['model']; |
| 129 | 129 | $item['model'] = ucwords(str_singular($item['name'])); |
| 130 | 130 | } |
| 131 | - if(strpos($item['model'], '\\') === false ){ |
|
| 131 | + if (strpos($item['model'], '\\') === false) { |
|
| 132 | 132 | $item['model'] = $this->getNamespace() . '\\' . $item['model']; |
| 133 | 133 | } |
| 134 | 134 | break; |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | protected function getRules() |
| 145 | 145 | { |
| 146 | 146 | $rules = $this->option('rules'); |
| 147 | - if(! $rules){ |
|
| 147 | + if (!$rules) { |
|
| 148 | 148 | return " // Validation rules"; |
| 149 | 149 | } |
| 150 | 150 | $items = $rules; |
| 151 | - if(! $this->option('parsed')){ |
|
| 151 | + if (!$this->option('parsed')) { |
|
| 152 | 152 | $items = $this->getArgumentParser('rules')->parse($rules); |
| 153 | 153 | } |
| 154 | 154 | $rules = []; |
@@ -19,9 +19,9 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | $file = $this->getFile(); |
| 21 | 21 | |
| 22 | - $content = ! $this->fs->exists($file) ? '' : $this->fs->get($file); |
|
| 22 | + $content = !$this->fs->exists($file) ? '' : $this->fs->get($file); |
|
| 23 | 23 | |
| 24 | - $content .= $this->getTemplate(! $this->fs->exists($file) ? 'factory-create' : 'factory') |
|
| 24 | + $content .= $this->getTemplate(!$this->fs->exists($file) ? 'factory-create' : 'factory') |
|
| 25 | 25 | ->with([ |
| 26 | 26 | 'model' => $model, |
| 27 | 27 | 'factory_fields' => $this->getFieldsContent() |
@@ -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); |
@@ -74,9 +74,9 @@ discard block |
||
| 74 | 74 | '--parsed' => true |
| 75 | 75 | ]); |
| 76 | 76 | |
| 77 | - if (! $this->option('no-controller')) { |
|
| 77 | + if (!$this->option('no-controller')) { |
|
| 78 | 78 | // generating REST actions trait if doesn't exist |
| 79 | - if(! $this->fs->exists('./app/Http/Controllers/RESTActions.php')){ |
|
| 79 | + if (!$this->fs->exists('./app/Http/Controllers/RESTActions.php')) { |
|
| 80 | 80 | $this->call('wn:controller:rest-actions'); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -100,8 +100,8 @@ discard block |
||
| 100 | 100 | |
| 101 | 101 | // generating model factory |
| 102 | 102 | $this->call('wn:factory', [ |
| 103 | - 'model' => $this->getNamespace().'\\'.$modelName, |
|
| 104 | - '--file' => './database/factories/'.str_plural($modelName).'.php', |
|
| 103 | + 'model' => $this->getNamespace() . '\\' . $modelName, |
|
| 104 | + '--file' => './database/factories/' . str_plural($modelName) . '.php', |
|
| 105 | 105 | '--fields' => $this->factoryFields(), |
| 106 | 106 | '--force' => $this->option('force'), |
| 107 | 107 | '--parsed' => true |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | protected function parseFields() |
| 118 | 118 | { |
| 119 | 119 | $fields = $this->argument('fields'); |
| 120 | - if($this->option('parsed')){ |
|
| 120 | + if ($this->option('parsed')) { |
|
| 121 | 121 | $this->fields = $fields; |
| 122 | 122 | } else { |
| 123 | - if(! $fields){ |
|
| 123 | + if (!$fields) { |
|
| 124 | 124 | $this->fields = []; |
| 125 | 125 | } else { |
| 126 | 126 | $this->fields = $this->getArgumentParser('fields') |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | if ($name['nullable']) { |
| 152 | 152 | $return['schema'][] = ['name' => 'nullable', 'args' => []]; |
| 153 | 153 | } else { |
| 154 | - $return['rules'] = 'required'.(!empty($return['rules'])?'|'.$return['rules']:''); |
|
| 154 | + $return['rules'] = 'required' . (!empty($return['rules']) ? '|' . $return['rules'] : ''); |
|
| 155 | 155 | } |
| 156 | 156 | } else { |
| 157 | 157 | $return['schema'] = [ |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | protected function fieldsHavingTag($tag) |
| 172 | 172 | { |
| 173 | - return array_map(function($field){ |
|
| 173 | + return array_map(function($field) { |
|
| 174 | 174 | return $field['name']; |
| 175 | 175 | }, array_filter($this->fields, function($field) use($tag){ |
| 176 | 176 | return in_array($tag, $field['tags']); |
@@ -179,19 +179,19 @@ discard block |
||
| 179 | 179 | |
| 180 | 180 | protected function rules() |
| 181 | 181 | { |
| 182 | - return array_map(function($field){ |
|
| 182 | + return array_map(function($field) { |
|
| 183 | 183 | return [ |
| 184 | 184 | 'name' => $field['name'], |
| 185 | 185 | 'rule' => $field['rules'] |
| 186 | 186 | ]; |
| 187 | - }, array_filter($this->fields, function($field){ |
|
| 187 | + }, array_filter($this->fields, function($field) { |
|
| 188 | 188 | return !empty($field['rules']); |
| 189 | 189 | })); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | protected function schema() |
| 193 | 193 | { |
| 194 | - return array_map(function($field){ |
|
| 194 | + return array_map(function($field) { |
|
| 195 | 195 | return array_merge([[ |
| 196 | 196 | 'name' => $field['name'], |
| 197 | 197 | 'args' => [] |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | protected function getBaseModel($path) { |
| 203 | 203 | $index = strrpos($path, "\\"); |
| 204 | - if($index) { |
|
| 204 | + if ($index) { |
|
| 205 | 205 | return substr($path, $index + 1); |
| 206 | 206 | } |
| 207 | 207 | return $path; |
@@ -212,19 +212,19 @@ discard block |
||
| 212 | 212 | $belongsTo = $this->option('belongs-to'); |
| 213 | 213 | $morphTo = $this->option('morph-to'); |
| 214 | 214 | |
| 215 | - if(! $belongsTo && (! $withMorph || ! $morphTo)) { |
|
| 215 | + if (!$belongsTo && (!$withMorph || !$morphTo)) { |
|
| 216 | 216 | return []; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | $belongsTo = $belongsTo ? $this->getArgumentParser('relations')->parse($belongsTo) : []; |
| 220 | 220 | |
| 221 | - $belongsTo = array_map(function($relation){ |
|
| 221 | + $belongsTo = array_map(function($relation) { |
|
| 222 | 222 | return array("model" => camel_case(str_singular($this->getBaseModel($relation['model'] ? $relation['model'] : $relation['name']))), "name" => snake_case(str_singular($this->getBaseModel($relation['name']))) . '_id', "type" => "belongsTo"); |
| 223 | 223 | }, $belongsTo); |
| 224 | 224 | |
| 225 | 225 | if ($withMorph) { |
| 226 | 226 | $morphTo = $morphTo ? $this->getArgumentParser('relations-morphTo')->parse($morphTo) : []; |
| 227 | - $morphTo = array_map(function($relation){ |
|
| 227 | + $morphTo = array_map(function($relation) { |
|
| 228 | 228 | $name = snake_case(str_singular($relation['name'])); |
| 229 | 229 | return array(array("name" => $name . '_id', "type" => "morphTo", "nullable" => $relation['nullable']), array("name" => $name . '_type', "type" => "morphTo", "nullable" => $relation['nullable'])); |
| 230 | 230 | }, $morphTo); |
@@ -253,12 +253,12 @@ discard block |
||
| 253 | 253 | |
| 254 | 254 | protected function factoryFields() |
| 255 | 255 | { |
| 256 | - return array_map(function($field){ |
|
| 256 | + return array_map(function($field) { |
|
| 257 | 257 | return [ |
| 258 | 258 | 'name' => $field['name'], |
| 259 | 259 | 'type' => $field['factory'] |
| 260 | 260 | ]; |
| 261 | - }, array_filter($this->fields, function($field){ |
|
| 261 | + }, array_filter($this->fields, function($field) { |
|
| 262 | 262 | return isset($field['factory']) && $field['factory']; |
| 263 | 263 | })); |
| 264 | 264 | } |