From 9dc684e5c65080b178b4208159671fe2972f0726 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 13:59:12 +0000 Subject: [PATCH 01/16] Refactored to make the list of commands a property Having the list of commands as a property allows it to be modified without needing to override the execute method. This allows one to change the scope of the Commands called also, e.g. for plugins. I've also flipped the foreach loop in the execute method for performance (i.e. to avoid an extra loop). --- src/Command/AllCommand.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index dc45bab0a..e782575b2 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -27,6 +27,16 @@ */ class AllCommand extends BakeCommand { + /** + * All commands to call. + * + * @var array + */ + public $commands = [ + 'ModelCommand', + 'ControllerCommand', + 'TemplateCommand' + ]; /** * Gets the option parser instance and configures it. * @@ -82,13 +92,9 @@ public function execute(Arguments $args, ConsoleIo $io): ?int $tables = [$name]; } - $commands = [ - new ModelCommand(), - new ControllerCommand(), - new TemplateCommand(), - ]; - foreach ($tables as $table) { - foreach ($commands as $command) { + foreach ($this->commands as $commandName) { + $command = new $commandName(); + foreach ($tables as $table) { $subArgs = new Arguments([$table], $args->getOptions(), ['name']); $command->execute($subArgs, $io); } From 1d7420d0768384b5d3e3bfbae878498ff933600d Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:02:24 +0000 Subject: [PATCH 02/16] Fixed for listing --- src/Command/AllCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index e782575b2..46789fc42 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -28,14 +28,14 @@ class AllCommand extends BakeCommand { /** - * All commands to call. + * All commands to call. * * @var array */ public $commands = [ 'ModelCommand', 'ControllerCommand', - 'TemplateCommand' + 'TemplateCommand', ]; /** * Gets the option parser instance and configures it. From ce2ca2202be0b37902f3a105c9fc3fdb2d63c3dc Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:44:00 +0000 Subject: [PATCH 03/16] Update AllCommand.php - Made $commands property protected instead of public - Added namespaces to strings - Ammended annotations as per reviews. --- src/Command/AllCommand.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 46789fc42..c4a012287 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -30,12 +30,12 @@ class AllCommand extends BakeCommand /** * All commands to call. * - * @var array + * @var string[] */ - public $commands = [ - 'ModelCommand', - 'ControllerCommand', - 'TemplateCommand', + protected $commands = [ + 'Bake\Command\ModelCommand', + 'Bake\Command\ControllerCommand', + 'Bake\Command\TemplateCommand', ]; /** * Gets the option parser instance and configures it. @@ -93,6 +93,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int } foreach ($this->commands as $commandName) { + /** @var \Cake\Comand\Command $command */ $command = new $commandName(); foreach ($tables as $table) { $subArgs = new Arguments([$table], $args->getOptions(), ['name']); From 2d903bcc784fbe9f21fe8674346e0f8712c49498 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:47:46 +0000 Subject: [PATCH 04/16] Update AllCommand.php Refactored to use `::class` instead strings. --- src/Command/AllCommand.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index c4a012287..3e903e91c 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -21,6 +21,9 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Datasource\ConnectionManager; +use Bake\Command\ModelCommand; +use Bake\Command\ControllerCommand; +use Bake\Command\TemplateCommand; /** * Command for `bake all` @@ -33,9 +36,9 @@ class AllCommand extends BakeCommand * @var string[] */ protected $commands = [ - 'Bake\Command\ModelCommand', - 'Bake\Command\ControllerCommand', - 'Bake\Command\TemplateCommand', + ModelCommand::class, + ControllerCommand::class, + TemplateCommand::class, ]; /** * Gets the option parser instance and configures it. From bd360d3e3a668050e561c3e075b24ed1a60f65e3 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:57:22 +0000 Subject: [PATCH 05/16] Revert "Update AllCommand.php" This reverts commit 2d903bcc784fbe9f21fe8674346e0f8712c49498. --- src/Command/AllCommand.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 3e903e91c..c4a012287 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -21,9 +21,6 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Datasource\ConnectionManager; -use Bake\Command\ModelCommand; -use Bake\Command\ControllerCommand; -use Bake\Command\TemplateCommand; /** * Command for `bake all` @@ -36,9 +33,9 @@ class AllCommand extends BakeCommand * @var string[] */ protected $commands = [ - ModelCommand::class, - ControllerCommand::class, - TemplateCommand::class, + 'Bake\Command\ModelCommand', + 'Bake\Command\ControllerCommand', + 'Bake\Command\TemplateCommand', ]; /** * Gets the option parser instance and configures it. From e7bdd968582f0fd6d38aa5a31256f56442d0d261 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:57:47 +0000 Subject: [PATCH 06/16] Revert "Update AllCommand.php" This reverts commit ce2ca2202be0b37902f3a105c9fc3fdb2d63c3dc. --- src/Command/AllCommand.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index c4a012287..46789fc42 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -30,12 +30,12 @@ class AllCommand extends BakeCommand /** * All commands to call. * - * @var string[] + * @var array */ - protected $commands = [ - 'Bake\Command\ModelCommand', - 'Bake\Command\ControllerCommand', - 'Bake\Command\TemplateCommand', + public $commands = [ + 'ModelCommand', + 'ControllerCommand', + 'TemplateCommand', ]; /** * Gets the option parser instance and configures it. @@ -93,7 +93,6 @@ public function execute(Arguments $args, ConsoleIo $io): ?int } foreach ($this->commands as $commandName) { - /** @var \Cake\Comand\Command $command */ $command = new $commandName(); foreach ($tables as $table) { $subArgs = new Arguments([$table], $args->getOptions(), ['name']); From 1f5e118ab73ce7e039a49f387c48b87e1e66577d Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:57:53 +0000 Subject: [PATCH 07/16] Revert "Fixed for listing" This reverts commit 1d7420d0768384b5d3e3bfbae878498ff933600d. --- src/Command/AllCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 46789fc42..e782575b2 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -28,14 +28,14 @@ class AllCommand extends BakeCommand { /** - * All commands to call. + * All commands to call. * * @var array */ public $commands = [ 'ModelCommand', 'ControllerCommand', - 'TemplateCommand', + 'TemplateCommand' ]; /** * Gets the option parser instance and configures it. From 5cd12492660c602099f90ea228d340ad3568c940 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 14:58:13 +0000 Subject: [PATCH 08/16] Revert "Refactored to make the list of commands a property" This reverts commit 9dc684e5c65080b178b4208159671fe2972f0726. --- src/Command/AllCommand.php | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index e782575b2..dc45bab0a 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -27,16 +27,6 @@ */ class AllCommand extends BakeCommand { - /** - * All commands to call. - * - * @var array - */ - public $commands = [ - 'ModelCommand', - 'ControllerCommand', - 'TemplateCommand' - ]; /** * Gets the option parser instance and configures it. * @@ -92,9 +82,13 @@ public function execute(Arguments $args, ConsoleIo $io): ?int $tables = [$name]; } - foreach ($this->commands as $commandName) { - $command = new $commandName(); - foreach ($tables as $table) { + $commands = [ + new ModelCommand(), + new ControllerCommand(), + new TemplateCommand(), + ]; + foreach ($tables as $table) { + foreach ($commands as $command) { $subArgs = new Arguments([$table], $args->getOptions(), ['name']); $command->execute($subArgs, $io); } From 82408770ec9aa833b2e728272e132630cd542b11 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 15:04:58 +0000 Subject: [PATCH 09/16] Update AllCommand.php - Having the list of commands as a protected property allows it to be modified without needing to override the execute method. - This allows one to change the scope of the Commands called also, e.g. for plugins. - I've also flipped the foreach loop in the execute method for performance (i.e. to avoid an extra loop). --- src/Command/AllCommand.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index dc45bab0a..3e903e91c 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -21,12 +21,25 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Datasource\ConnectionManager; +use Bake\Command\ModelCommand; +use Bake\Command\ControllerCommand; +use Bake\Command\TemplateCommand; /** * Command for `bake all` */ class AllCommand extends BakeCommand { + /** + * All commands to call. + * + * @var string[] + */ + protected $commands = [ + ModelCommand::class, + ControllerCommand::class, + TemplateCommand::class, + ]; /** * Gets the option parser instance and configures it. * @@ -82,13 +95,10 @@ public function execute(Arguments $args, ConsoleIo $io): ?int $tables = [$name]; } - $commands = [ - new ModelCommand(), - new ControllerCommand(), - new TemplateCommand(), - ]; - foreach ($tables as $table) { - foreach ($commands as $command) { + foreach ($this->commands as $commandName) { + /** @var \Cake\Comand\Command $command */ + $command = new $commandName(); + foreach ($tables as $table) { $subArgs = new Arguments([$table], $args->getOptions(), ['name']); $command->execute($subArgs, $io); } From 1e6637ceb4916422ce611285426a654a771491f7 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 15:21:23 +0000 Subject: [PATCH 10/16] Update AllCommand.php Changed order of use declarations. --- src/Command/AllCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 3e903e91c..693c0f872 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -21,8 +21,8 @@ use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Datasource\ConnectionManager; -use Bake\Command\ModelCommand; use Bake\Command\ControllerCommand; +use Bake\Command\ModelCommand; use Bake\Command\TemplateCommand; /** From 1f843617714180f0202a23ef1af7b705d9235490 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 15:26:04 +0000 Subject: [PATCH 11/16] Update alphabetical listing of `use` --- src/Command/AllCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 693c0f872..8b0f0e488 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -16,14 +16,14 @@ */ namespace Bake\Command; +use Bake\Command\ControllerCommand; +use Bake\Command\ModelCommand; +use Bake\Command\TemplateCommand; use Bake\Utility\TableScanner; use Cake\Console\Arguments; use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\Datasource\ConnectionManager; -use Bake\Command\ControllerCommand; -use Bake\Command\ModelCommand; -use Bake\Command\TemplateCommand; /** * Command for `bake all` From 77a313437dd712c7228ce373a667b586b8135527 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 15:53:04 +0000 Subject: [PATCH 12/16] Use strings instead of `::class` (to pass tests) --- src/Command/AllCommand.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 8b0f0e488..43531ec37 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -16,9 +16,6 @@ */ namespace Bake\Command; -use Bake\Command\ControllerCommand; -use Bake\Command\ModelCommand; -use Bake\Command\TemplateCommand; use Bake\Utility\TableScanner; use Cake\Console\Arguments; use Cake\Console\ConsoleIo; @@ -36,9 +33,9 @@ class AllCommand extends BakeCommand * @var string[] */ protected $commands = [ - ModelCommand::class, - ControllerCommand::class, - TemplateCommand::class, + 'Bake\Command\ControllerCommand', + 'Bake\Command\ModelCommand', + 'Bake\Command\TemplateCommand', ]; /** * Gets the option parser instance and configures it. From eaa28612facc1e3d877e4ee9499050ae73cbf619 Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 15:59:21 +0000 Subject: [PATCH 13/16] Revert "Use strings instead of `::class` (to pass tests)" This reverts commit 77a313437dd712c7228ce373a667b586b8135527. --- src/Command/AllCommand.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 43531ec37..8b0f0e488 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -16,6 +16,9 @@ */ namespace Bake\Command; +use Bake\Command\ControllerCommand; +use Bake\Command\ModelCommand; +use Bake\Command\TemplateCommand; use Bake\Utility\TableScanner; use Cake\Console\Arguments; use Cake\Console\ConsoleIo; @@ -33,9 +36,9 @@ class AllCommand extends BakeCommand * @var string[] */ protected $commands = [ - 'Bake\Command\ControllerCommand', - 'Bake\Command\ModelCommand', - 'Bake\Command\TemplateCommand', + ModelCommand::class, + ControllerCommand::class, + TemplateCommand::class, ]; /** * Gets the option parser instance and configures it. From 12eb76e0a7c9c4b753165ccb27241fbcce065e9d Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 16:33:39 +0000 Subject: [PATCH 14/16] Removed use statements --- src/Command/AllCommand.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index 8b0f0e488..f05080aeb 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -16,9 +16,6 @@ */ namespace Bake\Command; -use Bake\Command\ControllerCommand; -use Bake\Command\ModelCommand; -use Bake\Command\TemplateCommand; use Bake\Utility\TableScanner; use Cake\Console\Arguments; use Cake\Console\ConsoleIo; From 711539ccfba2dea6badc2298eac2f3b907fbf24f Mon Sep 17 00:00:00 2001 From: Noel da Costa Date: Thu, 5 Mar 2020 16:39:17 +0000 Subject: [PATCH 15/16] [FIX] - typo in annotation --- src/Command/AllCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index f05080aeb..d1a07b8af 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -93,7 +93,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int } foreach ($this->commands as $commandName) { - /** @var \Cake\Comand\Command $command */ + /** @var \Cake\Command\Command $command */ $command = new $commandName(); foreach ($tables as $table) { $subArgs = new Arguments([$table], $args->getOptions(), ['name']); From 91e9ab1fd99f61d9f32bd6a42152f0f758cff69e Mon Sep 17 00:00:00 2001 From: Mark Sch Date: Thu, 5 Mar 2020 17:43:10 +0100 Subject: [PATCH 16/16] Fix CS --- src/Command/AllCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Command/AllCommand.php b/src/Command/AllCommand.php index d1a07b8af..fd6ecd4ab 100644 --- a/src/Command/AllCommand.php +++ b/src/Command/AllCommand.php @@ -37,6 +37,7 @@ class AllCommand extends BakeCommand ControllerCommand::class, TemplateCommand::class, ]; + /** * Gets the option parser instance and configures it. *