@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | |
64 | 64 | $I->wantTo('run wn:routes in Lumen 5.3+'); |
65 | -if(!file_exists('./routes')) { |
|
65 | +if (!file_exists('./routes')) { |
|
66 | 66 | mkdir('./routes'); |
67 | 67 | } |
68 | 68 | $I->writeToFile('./routes/web.php', '<?php |
@@ -1,8 +1,6 @@ |
||
1 | 1 | <?php namespace Wn\Generators\Commands; |
2 | 2 | |
3 | 3 | |
4 | -use InvalidArgumentException; |
|
5 | - |
|
6 | 4 | class ControllerCommand extends BaseCommand { |
7 | 5 | |
8 | 6 | const DEFAULT_PATH = "app/Http/Controllers"; |
@@ -5,9 +5,9 @@ discard block |
||
5 | 5 | |
6 | 6 | class ControllerCommand extends BaseCommand { |
7 | 7 | |
8 | - const DEFAULT_PATH = "app/Http/Controllers"; |
|
8 | + const DEFAULT_PATH = "app/Http/Controllers"; |
|
9 | 9 | |
10 | - protected $signature = 'wn:controller |
|
10 | + protected $signature = 'wn:controller |
|
11 | 11 | {model : Name of the model (with namespace if not App)} |
12 | 12 | {--path='.ControllerCommand::DEFAULT_PATH.' : where to store the controllers file.} |
13 | 13 | {--no-routes= : without routes} |
@@ -16,28 +16,28 @@ discard block |
||
16 | 16 | {--laravel : Use Laravel style route definitions} |
17 | 17 | '; |
18 | 18 | |
19 | - protected $description = 'Generates RESTful controller using the RESTActions trait'; |
|
19 | + protected $description = 'Generates RESTful controller using the RESTActions trait'; |
|
20 | 20 | |
21 | 21 | public function handle() |
22 | 22 | { |
23 | - $model = $this->argument('model'); |
|
24 | - $name = ''; |
|
25 | - if(strrpos($model, "\\") === false){ |
|
26 | - $name = $model; |
|
27 | - $model = "App\\" . $model; |
|
28 | - } else { |
|
29 | - $name = explode("\\", $model); |
|
30 | - $name = $name[count($name) - 1]; |
|
31 | - } |
|
23 | + $model = $this->argument('model'); |
|
24 | + $name = ''; |
|
25 | + if(strrpos($model, "\\") === false){ |
|
26 | + $name = $model; |
|
27 | + $model = "App\\" . $model; |
|
28 | + } else { |
|
29 | + $name = explode("\\", $model); |
|
30 | + $name = $name[count($name) - 1]; |
|
31 | + } |
|
32 | 32 | $controller = ucwords(str_plural($name)) . 'Controller'; |
33 | 33 | $content = $this->getTemplate('controller') |
34 | - ->with([ |
|
35 | - 'name' => $controller, |
|
36 | - 'model' => $model, |
|
37 | - 'namespace' => $this->getNamespace(), |
|
38 | - 'use' => ($this->getNamespace() != $this->getDefaultNamespace()?'use '.$this->getDefaultNamespace().'\Controller;'.PHP_EOL.'use '.$this->getDefaultNamespace().'\RESTActions;'.PHP_EOL:'') |
|
39 | - ]) |
|
40 | - ->get(); |
|
34 | + ->with([ |
|
35 | + 'name' => $controller, |
|
36 | + 'model' => $model, |
|
37 | + 'namespace' => $this->getNamespace(), |
|
38 | + 'use' => ($this->getNamespace() != $this->getDefaultNamespace()?'use '.$this->getDefaultNamespace().'\Controller;'.PHP_EOL.'use '.$this->getDefaultNamespace().'\RESTActions;'.PHP_EOL:'') |
|
39 | + ]) |
|
40 | + ->get(); |
|
41 | 41 | |
42 | 42 | $this->save($content, "./{$this->option('path')}/{$controller}.php", "{$controller}"); |
43 | 43 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | } |
62 | 62 | } |
63 | 63 | |
64 | - protected function getDefaultNamespace() { |
|
65 | - return $this->getNamespace(ControllerCommand::DEFAULT_PATH); |
|
66 | - } |
|
64 | + protected function getDefaultNamespace() { |
|
65 | + return $this->getNamespace(ControllerCommand::DEFAULT_PATH); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | |
10 | 10 | protected $signature = 'wn:controller |
11 | 11 | {model : Name of the model (with namespace if not App)} |
12 | - {--path='.ControllerCommand::DEFAULT_PATH.' : where to store the controllers file.} |
|
12 | + {--path='.ControllerCommand::DEFAULT_PATH . ' : where to store the controllers file.} |
|
13 | 13 | {--no-routes= : without routes} |
14 | 14 | {--routes= : where to store the routes.} |
15 | 15 | {--force= : override the existing files} |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | { |
23 | 23 | $model = $this->argument('model'); |
24 | 24 | $name = ''; |
25 | - if(strrpos($model, "\\") === false){ |
|
25 | + if (strrpos($model, "\\") === false) { |
|
26 | 26 | $name = $model; |
27 | 27 | $model = "App\\" . $model; |
28 | 28 | } else { |
@@ -35,13 +35,13 @@ discard block |
||
35 | 35 | 'name' => $controller, |
36 | 36 | 'model' => $model, |
37 | 37 | 'namespace' => $this->getNamespace(), |
38 | - 'use' => ($this->getNamespace() != $this->getDefaultNamespace()?'use '.$this->getDefaultNamespace().'\Controller;'.PHP_EOL.'use '.$this->getDefaultNamespace().'\RESTActions;'.PHP_EOL:'') |
|
38 | + 'use' => ($this->getNamespace() != $this->getDefaultNamespace() ? 'use ' . $this->getDefaultNamespace() . '\Controller;' . PHP_EOL . 'use ' . $this->getDefaultNamespace() . '\RESTActions;' . PHP_EOL : '') |
|
39 | 39 | ]) |
40 | 40 | ->get(); |
41 | 41 | |
42 | 42 | $this->save($content, "./{$this->option('path')}/{$controller}.php", "{$controller}"); |
43 | 43 | |
44 | - if(! $this->option('no-routes')){ |
|
44 | + if (!$this->option('no-routes')) { |
|
45 | 45 | $options = [ |
46 | 46 | 'resource' => snake_case($name, '-'), |
47 | 47 | '--controller' => $controller, |
@@ -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'); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | class MorphTableCommand extends BaseCommand { |
5 | 5 | |
6 | - protected $signature = 'wn:morph-table |
|
6 | + protected $signature = 'wn:morph-table |
|
7 | 7 | {model : Name of the persistant model or table} |
8 | 8 | {morphable : Name of the morphable identifier} |
9 | 9 | {--add= : specifies additional columns like timestamps, softDeletes, rememberToken and nullableTimestamps.} |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | {--force= : override the existing files} |
12 | 12 | '; |
13 | 13 | |
14 | - protected $description = 'Generates creation migration for a morphable pivot table'; |
|
14 | + protected $description = 'Generates creation migration for a morphable pivot table'; |
|
15 | 15 | |
16 | 16 | protected $fields; |
17 | 17 | |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | protected function keys() |
49 | 49 | { |
50 | 50 | // return implode(' ', $this->fields); |
51 | - return snake_case(str_singular($this->argument('model')))."_id"; |
|
51 | + return snake_case(str_singular($this->argument('model')))."_id"; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -33,14 +33,14 @@ discard block |
||
33 | 33 | protected function parseFields() |
34 | 34 | { |
35 | 35 | $this->fields = array_map(function($arg, $app) { |
36 | - return snake_case(str_singular($this->argument($arg)))."_".$app; |
|
36 | + return snake_case(str_singular($this->argument($arg))) . "_" . $app; |
|
37 | 37 | }, ['model', 'morphable', 'morphable'], ['id', 'id', 'type']); |
38 | 38 | |
39 | 39 | } |
40 | 40 | |
41 | 41 | protected function schema() |
42 | 42 | { |
43 | - return implode(' ', array_map(function($field){ |
|
43 | + return implode(' ', array_map(function($field) { |
|
44 | 44 | return $field . ':' . (substr($field, -3) == '_id' ? 'integer:unsigned' : 'string.50') . ':index'; |
45 | 45 | }, $this->fields)); |
46 | 46 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | protected function keys() |
49 | 49 | { |
50 | 50 | // return implode(' ', $this->fields); |
51 | - return snake_case(str_singular($this->argument('model')))."_id"; |
|
51 | + return snake_case(str_singular($this->argument('model'))) . "_id"; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $snakeName = snake_case($name); |
25 | 25 | |
26 | 26 | $file = $this->option('file'); |
27 | - if (! $file) { |
|
27 | + if (!$file) { |
|
28 | 28 | $file = date('Y_m_d_His_') . $snakeName . '_table'; |
29 | 29 | $this->deleteOldMigration($snakeName); |
30 | 30 | } else { |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | |
47 | 47 | protected function deleteOldMigration($fileName) |
48 | 48 | { |
49 | - foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){ |
|
50 | - if($fileInfo->isDot()) continue; |
|
49 | + foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo) { |
|
50 | + if ($fileInfo->isDot()) continue; |
|
51 | 51 | |
52 | - if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){ |
|
52 | + if (strpos($fileInfo->getFilename(), $fileName) !== FALSE) { |
|
53 | 53 | unlink($fileInfo->getPathname()); |
54 | 54 | } |
55 | 55 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | $name = $parts[0]['name']; |
93 | 93 | $parts[1]['args'] = array_merge(["'{$name}'"], $parts[1]['args']); |
94 | 94 | unset($parts[0]); |
95 | - $parts = array_map(function($part){ |
|
95 | + $parts = array_map(function($part) { |
|
96 | 96 | return '->' . $part['name'] . '(' . implode(', ', $part['args']) . ')'; |
97 | 97 | }, $parts); |
98 | 98 | return " \$table" . implode('', $parts) . ';'; |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | |
116 | 116 | protected function getConstraintDeclaration($key) |
117 | 117 | { |
118 | - if(! $key['column']){ |
|
118 | + if (!$key['column']) { |
|
119 | 119 | $key['column'] = 'id'; |
120 | 120 | } |
121 | - if(! $key['table']){ |
|
121 | + if (!$key['table']) { |
|
122 | 122 | $key['table'] = substr($key['name'], 0, count($key['name']) - 4); |
123 | 123 | } |
124 | 124 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | ]) |
131 | 131 | ->get(); |
132 | 132 | |
133 | - if($key['on_delete']){ |
|
133 | + if ($key['on_delete']) { |
|
134 | 134 | $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') |
135 | 135 | ->with([ |
136 | 136 | 'event' => 'Delete', |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | ->get(); |
140 | 140 | } |
141 | 141 | |
142 | - if($key['on_update']){ |
|
142 | + if ($key['on_update']) { |
|
143 | 143 | $constraint .= PHP_EOL . $this->getTemplate('migration/on-constraint') |
144 | 144 | ->with([ |
145 | 145 | 'event' => 'Update', |
@@ -47,7 +47,9 @@ |
||
47 | 47 | protected function deleteOldMigration($fileName) |
48 | 48 | { |
49 | 49 | foreach (new \DirectoryIterator("./database/migrations/") as $fileInfo){ |
50 | - if($fileInfo->isDot()) continue; |
|
50 | + if($fileInfo->isDot()) { |
|
51 | + continue; |
|
52 | + } |
|
51 | 53 | |
52 | 54 | if(strpos($fileInfo->getFilename(), $fileName) !== FALSE){ |
53 | 55 | unlink($fileInfo->getPathname()); |
@@ -46,45 +46,45 @@ discard block |
||
46 | 46 | $morphTables = $this->uniqueArray($this->getTables($nodes, 'morphTables')); |
47 | 47 | |
48 | 48 | if (! $this->option('skip-check')) { |
49 | - $this->info('Checking Relationships...'); |
|
50 | - $keys = array_keys($nodes); |
|
51 | - foreach ($nodes as $model => $i) { |
|
52 | - $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
53 | - // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
54 | - } |
|
55 | - $this->checkPivotRelations($nodes, $pivotTables, 'pivot'); |
|
56 | - $this->checkPivotRelations($nodes, $morphTables, 'morph'); |
|
49 | + $this->info('Checking Relationships...'); |
|
50 | + $keys = array_keys($nodes); |
|
51 | + foreach ($nodes as $model => $i) { |
|
52 | + $this->checkRelations($i['belongsTo'], 'belongsTo', $i['filename'], $i['uniquename'], $keys); |
|
53 | + // $this->checkRelations($i['hasManyThrough'], 'hasManyThrough', $file, $model); |
|
54 | + } |
|
55 | + $this->checkPivotRelations($nodes, $pivotTables, 'pivot'); |
|
56 | + $this->checkPivotRelations($nodes, $morphTables, 'morph'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | if ($this->checkedErrors > 0) { |
60 | - $this->line(''); |
|
61 | - if ($this->option('check-only')) { |
|
62 | - $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
63 | - } |
|
64 | - $this->printErrors(); |
|
60 | + $this->line(''); |
|
61 | + if ($this->option('check-only')) { |
|
62 | + $this->info('Checking only, we have found ' . $this->checkedErrors . ' errors.'); |
|
63 | + } |
|
64 | + $this->printErrors(); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
68 | 68 | if (! $this->option('check-only') && $this->checkedErrors > 0) { |
69 | - $this->line(''); |
|
70 | - $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
69 | + $this->line(''); |
|
70 | + $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
|
71 | 71 | } |
72 | 72 | if ($proceed) { |
73 | - $this->buildResources($nodes); |
|
73 | + $this->buildResources($nodes); |
|
74 | 74 | |
75 | - // if (!$this->option('no-migration')) { |
|
76 | - // $this->call('migrate'); // actually needed for pivot seeders ! |
|
77 | - // } |
|
75 | + // if (!$this->option('no-migration')) { |
|
76 | + // $this->call('migrate'); // actually needed for pivot seeders ! |
|
77 | + // } |
|
78 | 78 | |
79 | - $this->line(''); |
|
79 | + $this->line(''); |
|
80 | 80 | $this->buildTables('Pivot-Table', 'wn:pivot-table', 'model1', 'model2', $pivotTables); |
81 | 81 | |
82 | - $this->line(''); |
|
82 | + $this->line(''); |
|
83 | 83 | $this->buildTables('Morph-Table', 'wn:morph-table', 'model', 'morphable', $morphTables); |
84 | 84 | |
85 | - if (!$this->option('no-migration')) { |
|
86 | - $this->call('migrate'); |
|
87 | - } |
|
85 | + if (!$this->option('no-migration')) { |
|
86 | + $this->call('migrate'); |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
@@ -371,10 +371,10 @@ discard block |
||
371 | 371 | $deps = $this->getArgumentParser('relations')->parse($nodes[$key]['belongsTo']); |
372 | 372 | foreach($deps as $dependency) { |
373 | 373 | if(! $dependency['model']){ |
374 | - $dependency['model'] = $dependency['name']; |
|
375 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
376 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
377 | - } |
|
374 | + $dependency['model'] = $dependency['name']; |
|
375 | + } else if(strpos($dependency['model'], '\\') !== false ){ |
|
376 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
377 | + } |
|
378 | 378 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
379 | 379 | if ($dependency['model'] != $key) { |
380 | 380 | $tmp = $this->getDependencies($nodes, $dependency['model'], $seen); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | return; |
41 | 41 | } |
42 | 42 | if (is_string($files)) { |
43 | - $files = [ $files ]; |
|
43 | + $files = [$files]; |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | foreach ($files as $file) { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | $pivotTables = $this->uniqueArray($this->getTables($nodes, 'pivotTables')); |
55 | 55 | $morphTables = $this->uniqueArray($this->getTables($nodes, 'morphTables')); |
56 | 56 | |
57 | - if (! $this->option('skip-check')) { |
|
57 | + if (!$this->option('skip-check')) { |
|
58 | 58 | $this->info('Checking Relationships...'); |
59 | 59 | $keys = array_keys($nodes); |
60 | 60 | foreach ($nodes as $model => $i) { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $this->printErrors(); |
74 | 74 | } |
75 | 75 | |
76 | - $proceed = (! $this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
|
77 | - if (! $this->option('check-only') && $this->checkedErrors > 0) { |
|
76 | + $proceed = (!$this->option('check-only') && $this->checkedErrors == 0) || $this->option('skip-check'); |
|
77 | + if (!$this->option('check-only') && $this->checkedErrors > 0) { |
|
78 | 78 | $this->line(''); |
79 | 79 | $proceed = $this->confirm("We have found " . $this->checkedErrors . " errors. Are you sure you want to continue?"); |
80 | 80 | } |
@@ -107,14 +107,14 @@ discard block |
||
107 | 107 | |
108 | 108 | protected function readFile($file) |
109 | 109 | { |
110 | - $this->info("Reading file ".$file); |
|
110 | + $this->info("Reading file " . $file); |
|
111 | 111 | |
112 | 112 | $content = $this->fs->get($file); |
113 | 113 | $content = Yaml::parse($content); |
114 | 114 | |
115 | 115 | $nodes = []; |
116 | 116 | |
117 | - foreach ($content as $model => $i){ |
|
117 | + foreach ($content as $model => $i) { |
|
118 | 118 | /* |
119 | 119 | $i['modelname'] = as originally in YAML defined |
120 | 120 | $i['name'] = as originally defined in snake_case |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | } |
133 | 133 | |
134 | 134 | protected function mergeNodes($nodes, $toMerge, $forceRedefinition = false) { |
135 | - foreach($toMerge as $node) { |
|
135 | + foreach ($toMerge as $node) { |
|
136 | 136 | $nodes = $this->mergeNode($nodes, $node, $forceRedefinition); |
137 | 137 | } |
138 | 138 | |
@@ -142,11 +142,11 @@ discard block |
||
142 | 142 | protected function mergeNode($nodes, $toMerge, $forceRedefinition = false) { |
143 | 143 | if (empty($nodes[$toMerge['uniquename']]) || $forceRedefinition) { |
144 | 144 | if (!empty($nodes[$toMerge['uniquename']])) { |
145 | - $this->checkError($toMerge['uniquename'] . ": forced to redefine (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", redefined from file ".$toMerge['filename'].")"); |
|
145 | + $this->checkError($toMerge['uniquename'] . ": forced to redefine (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", redefined from file " . $toMerge['filename'] . ")"); |
|
146 | 146 | } |
147 | 147 | $nodes[$toMerge['uniquename']] = $toMerge; |
148 | 148 | } else { |
149 | - $this->checkError($toMerge['uniquename'] . ": already defined (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", trying to redefine from file ".$toMerge['filename']."; Use --force-redefine to force redefinition)"); |
|
149 | + $this->checkError($toMerge['uniquename'] . ": already defined (in file " . $nodes[$toMerge['uniquename']]['filename'] . ", trying to redefine from file " . $toMerge['filename'] . "; Use --force-redefine to force redefinition)"); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | return $nodes; |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | protected function getTables($nodes, $key) { |
156 | 156 | $tables = []; |
157 | - foreach($nodes as $node) { |
|
157 | + foreach ($nodes as $node) { |
|
158 | 158 | if (!empty($node[$key])) { |
159 | 159 | $tables = array_merge($tables, $node[$key]); |
160 | 160 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | protected function buildResources($nodes) |
167 | 167 | { |
168 | 168 | $modelIndex = 0; |
169 | - $migrationIdLength = strlen((string)count($nodes)); |
|
169 | + $migrationIdLength = strlen((string) count($nodes)); |
|
170 | 170 | foreach ($nodes as $i) { |
171 | - $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
172 | - $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex , $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
171 | + $migrationName = 'Create' . ucwords(str_plural($i['name'])); |
|
172 | + $migrationFile = date('Y_m_d_His') . '-' . str_pad($modelIndex, $migrationIdLength, 0, STR_PAD_LEFT) . '_' . snake_case($migrationName) . '_table'; |
|
173 | 173 | |
174 | 174 | $this->line(''); |
175 | 175 | $this->info('Building Model ' . $i['uniquename']); |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | protected function buildTables($type, $command, $model1, $model2, $tableAssignment) |
214 | 214 | { |
215 | 215 | foreach ($tableAssignment as $tables) { |
216 | - $this->info('Building '.$type.' ' . $tables[0] . ' - ' . $tables[1]); |
|
216 | + $this->info('Building ' . $type . ' ' . $tables[0] . ' - ' . $tables[1]); |
|
217 | 217 | $this->call($command, [ |
218 | 218 | $model1 => $tables[0], |
219 | 219 | $model2 => $tables[1], |
@@ -237,28 +237,28 @@ discard block |
||
237 | 237 | $i['modelname'] = $i['modelname']; |
238 | 238 | $i['uniquename'] = $i['uniquename']; |
239 | 239 | |
240 | - foreach(['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation){ |
|
241 | - if(isset($i[$relation])){ |
|
240 | + foreach (['hasMany', 'hasOne', 'add', 'belongsTo', 'belongsToMany', 'hasManyThrough', 'morphTo', 'morphMany', 'morphToMany', 'morphedByMany'] as $relation) { |
|
241 | + if (isset($i[$relation])) { |
|
242 | 242 | $i[$relation] = $this->convertArray($i[$relation], ' ', ','); |
243 | 243 | } else { |
244 | 244 | $i[$relation] = false; |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | - if($i['belongsToMany']){ |
|
248 | + if ($i['belongsToMany']) { |
|
249 | 249 | $i['pivotTables'] = $this->belongsTo($i['name'], $modelName, $i['belongsToMany']); |
250 | 250 | } |
251 | 251 | |
252 | - if($i['morphToMany']){ |
|
252 | + if ($i['morphToMany']) { |
|
253 | 253 | $i['morphTables'] = $this->morphToMany($modelName, $i['morphToMany']); |
254 | 254 | } |
255 | 255 | |
256 | - if($i['morphedByMany']){ |
|
256 | + if ($i['morphedByMany']) { |
|
257 | 257 | $i['morphTables'] = array_merge($i['morphTables'], $this->morphedByMany($i['name'], $modelName, $i['morphedByMany'])); |
258 | 258 | } |
259 | 259 | |
260 | 260 | $fields = []; |
261 | - foreach($i['fields'] as $name => $value) { |
|
261 | + foreach ($i['fields'] as $name => $value) { |
|
262 | 262 | $value['name'] = $name; |
263 | 263 | $fields[] = $this->serializeField($value); |
264 | 264 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | { |
272 | 272 | $parsedRelations = []; |
273 | 273 | $relations = $this->getArgumentParser($parser)->parse($relations); |
274 | - foreach ($relations as $relation){ |
|
274 | + foreach ($relations as $relation) { |
|
275 | 275 | $parsedRelations[] = $callback($relation); |
276 | 276 | } |
277 | 277 | |
@@ -281,13 +281,13 @@ discard block |
||
281 | 281 | protected function belongsTo($name, $modelName, $belongsTo) |
282 | 282 | { |
283 | 283 | return $this->parseRelations('relations', $belongsTo, function($relation) use ($name, $modelName) { |
284 | - if(! $relation['model']){ |
|
284 | + if (!$relation['model']) { |
|
285 | 285 | $table = snake_case($relation['name']); |
286 | 286 | } else { |
287 | 287 | $table = snake_case($this->extractClassName($relation['model'])); |
288 | 288 | } |
289 | 289 | |
290 | - $tables = [ str_singular($table), $name ]; |
|
290 | + $tables = [str_singular($table), $name]; |
|
291 | 291 | sort($tables); |
292 | 292 | $tables[] = $modelName; |
293 | 293 | return $tables; |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | protected function morphToMany($modelName, $morphToMany) |
298 | 298 | { |
299 | 299 | return $this->parseRelations('relations-morphMany', $morphToMany, function($relation) use ($modelName) { |
300 | - if(! $relation['through']){ |
|
300 | + if (!$relation['through']) { |
|
301 | 301 | $name = snake_case($relation['name']); |
302 | 302 | } else { |
303 | 303 | $name = snake_case($this->extractClassName($relation['model'])); |
@@ -315,13 +315,13 @@ discard block |
||
315 | 315 | } |
316 | 316 | |
317 | 317 | protected function getMorphableRelation($relation, $relationName, $modelName) { |
318 | - if(! $relation['through']){ |
|
318 | + if (!$relation['through']) { |
|
319 | 319 | $morphable = snake_case($this->extractClassName($relation['model'])); |
320 | 320 | } else { |
321 | 321 | $morphable = snake_case($this->extractClassName($relation['through'])); |
322 | 322 | } |
323 | 323 | |
324 | - return [ str_singular($relationName), str_singular($morphable), $modelName ]; |
|
324 | + return [str_singular($relationName), str_singular($morphable), $modelName]; |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | protected function serializeField($field) |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | |
334 | 334 | $string = "{$name};{$schema};{$rules};{$tags}"; |
335 | 335 | |
336 | - if(isset($field['factory']) && !empty($field['factory'])){ |
|
336 | + if (isset($field['factory']) && !empty($field['factory'])) { |
|
337 | 337 | $string .= ';' . $field['factory']; |
338 | 338 | } |
339 | 339 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | |
343 | 343 | protected function convertArray($list, $old, $new) |
344 | 344 | { |
345 | - return implode($new, array_filter(explode($old, $list), function($item){ |
|
345 | + return implode($new, array_filter(explode($old, $list), function($item) { |
|
346 | 346 | return !empty($item); |
347 | 347 | })); |
348 | 348 | } |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $load_order = array(); |
352 | 352 | $seen = array(); |
353 | 353 | |
354 | - foreach($nodes as $key => $item) { |
|
354 | + foreach ($nodes as $key => $item) { |
|
355 | 355 | $tmp = $this->getDependencies($nodes, $key, $seen); |
356 | 356 | |
357 | 357 | // if($tmp[2] === false) { |
@@ -364,22 +364,22 @@ discard block |
||
364 | 364 | } |
365 | 365 | |
366 | 366 | private function getDependencies($nodes, $key, $seen = array()) { |
367 | - if(array_key_exists($key, $seen) === true) { |
|
367 | + if (array_key_exists($key, $seen) === true) { |
|
368 | 368 | return array(array(), $seen); |
369 | 369 | } |
370 | 370 | |
371 | 371 | |
372 | - if(!empty($nodes[$key])) { |
|
372 | + if (!empty($nodes[$key])) { |
|
373 | 373 | $order = array(); |
374 | 374 | // $failed = array(); |
375 | 375 | |
376 | - if($nodes[$key]['belongsTo']) { |
|
376 | + if ($nodes[$key]['belongsTo']) { |
|
377 | 377 | $deps = $this->getArgumentParser('relations')->parse($nodes[$key]['belongsTo']); |
378 | - foreach($deps as $dependency) { |
|
379 | - if(! $dependency['model']){ |
|
378 | + foreach ($deps as $dependency) { |
|
379 | + if (!$dependency['model']) { |
|
380 | 380 | $dependency['model'] = $dependency['name']; |
381 | - } else if(strpos($dependency['model'], '\\') !== false ){ |
|
382 | - $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\')+1); // Cut offs first namespace part |
|
381 | + } else if (strpos($dependency['model'], '\\') !== false) { |
|
382 | + $dependency['model'] = substr($dependency['model'], strpos($dependency['model'], '\\') + 1); // Cut offs first namespace part |
|
383 | 383 | } |
384 | 384 | $dependency['model'] = studly_case(str_singular($dependency['model'])); |
385 | 385 | if ($dependency['model'] != $key) { |
@@ -398,10 +398,10 @@ discard block |
||
398 | 398 | $order[$key] = $nodes[$key]; |
399 | 399 | // $failed = (count($failed) > 0) ? $failed : false; |
400 | 400 | |
401 | - return array($order, $seen);//, $failed |
|
401 | + return array($order, $seen); //, $failed |
|
402 | 402 | } |
403 | 403 | |
404 | - return array(array(), $seen);//, array($item) |
|
404 | + return array(array(), $seen); //, array($item) |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | protected function checkError($message, $model = "", $file = "") { |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | if ($relations) { |
427 | 427 | $position = array_search($model, $keys); |
428 | 428 | $relations = $this->getArgumentParser('relations')->parse($relations); |
429 | - foreach($relations as $relation) { |
|
429 | + foreach ($relations as $relation) { |
|
430 | 430 | $rModel = $relation['model'] ? $relation['model'] : $relation['name']; |
431 | 431 | $search = array_search(studly_case(str_singular($rModel)), $keys); |
432 | 432 | if (($search === false || $search > $position) && !class_exists($this->prependNamespace($rModel)) && !class_exists($this->prependNamespace($rModel, 'App'))) { |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | |
443 | 443 | protected function checkPivotRelations($nodes, $relations, $relationType) { |
444 | 444 | if ($relations) { |
445 | - foreach($relations as $relation) { |
|
445 | + foreach ($relations as $relation) { |
|
446 | 446 | $relation['0'] = studly_case(str_singular($relation['0'])); |
447 | 447 | $relation['1'] = studly_case(str_singular($relation['1'])); |
448 | 448 | $relation['2'] = studly_case(str_singular($relation['2'])); |