From f9a9ad50c3f4cc49db42d62430331f175de13a70 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Mon, 12 Jun 2023 17:52:30 +0330 Subject: [PATCH 1/5] Uses PHP8's constructor property promotion in core/Command/Encryption classes. Signed-off-by: Faraz Samapoor --- .../Encryption/ChangeKeyStorageRoot.php | 19 +++++++---------- core/Command/Encryption/DecryptAll.php | 21 +++++-------------- core/Command/Encryption/Disable.php | 5 +---- core/Command/Encryption/Enable.php | 13 +++++------- core/Command/Encryption/EncryptAll.php | 16 ++++---------- core/Command/Encryption/ListModules.php | 9 ++------ core/Command/Encryption/MigrateKeyStorage.php | 20 +++++++----------- core/Command/Encryption/SetDefaultModule.php | 9 ++------ .../Command/Encryption/ShowKeyStorageRoot.php | 5 +---- core/Command/Encryption/Status.php | 5 +---- 10 files changed, 35 insertions(+), 87 deletions(-) diff --git a/core/Command/Encryption/ChangeKeyStorageRoot.php b/core/Command/Encryption/ChangeKeyStorageRoot.php index 6ae59421a6918..96884de25e9e2 100644 --- a/core/Command/Encryption/ChangeKeyStorageRoot.php +++ b/core/Command/Encryption/ChangeKeyStorageRoot.php @@ -40,19 +40,14 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; class ChangeKeyStorageRoot extends Command { - protected View $rootView; - protected IUserManager $userManager; - protected IConfig $config; - protected Util $util; - protected QuestionHelper $questionHelper; - - public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, QuestionHelper $questionHelper) { + public function __construct( + protected View $rootView, + protected IUserManager $userManager, + protected IConfig $config, + protected Util $util, + protected QuestionHelper $questionHelper, + ) { parent::__construct(); - $this->rootView = $view; - $this->userManager = $userManager; - $this->config = $config; - $this->util = $util; - $this->questionHelper = $questionHelper; } protected function configure() { diff --git a/core/Command/Encryption/DecryptAll.php b/core/Command/Encryption/DecryptAll.php index ce17f787abde4..7569605e7751d 100644 --- a/core/Command/Encryption/DecryptAll.php +++ b/core/Command/Encryption/DecryptAll.php @@ -41,28 +41,17 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; class DecryptAll extends Command { - protected IManager $encryptionManager; - protected IAppManager $appManager; - protected IConfig $config; - protected QuestionHelper $questionHelper; protected bool $wasTrashbinEnabled; protected bool $wasMaintenanceModeEnabled; - protected \OC\Encryption\DecryptAll $decryptAll; public function __construct( - IManager $encryptionManager, - IAppManager $appManager, - IConfig $config, - \OC\Encryption\DecryptAll $decryptAll, - QuestionHelper $questionHelper + protected IManager $encryptionManager, + protected IAppManager $appManager, + protected IConfig $config, + protected \OC\Encryption\DecryptAll $decryptAll, + protected QuestionHelper $questionHelper, ) { parent::__construct(); - - $this->appManager = $appManager; - $this->encryptionManager = $encryptionManager; - $this->config = $config; - $this->decryptAll = $decryptAll; - $this->questionHelper = $questionHelper; } /** diff --git a/core/Command/Encryption/Disable.php b/core/Command/Encryption/Disable.php index 446601a1b4f0d..e188e6be3442e 100644 --- a/core/Command/Encryption/Disable.php +++ b/core/Command/Encryption/Disable.php @@ -27,11 +27,8 @@ use Symfony\Component\Console\Output\OutputInterface; class Disable extends Command { - protected IConfig $config; - - public function __construct(IConfig $config) { + public function __construct(protected IConfig $config) { parent::__construct(); - $this->config = $config; } protected function configure() { diff --git a/core/Command/Encryption/Enable.php b/core/Command/Encryption/Enable.php index 284d96809aed9..2cbb315283e50 100644 --- a/core/Command/Encryption/Enable.php +++ b/core/Command/Encryption/Enable.php @@ -29,14 +29,11 @@ use Symfony\Component\Console\Output\OutputInterface; class Enable extends Command { - protected IConfig $config; - protected IManager $encryptionManager; - - public function __construct(IConfig $config, IManager $encryptionManager) { + public function __construct( + protected IConfig $config, + protected IManager $encryptionManager, + ) { parent::__construct(); - - $this->encryptionManager = $encryptionManager; - $this->config = $config; } protected function configure() { @@ -70,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } $output->writeln('Default module: ' . $defaultModule); - + return 0; } } diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php index 11e33ae9e2ee8..17d3a80394262 100644 --- a/core/Command/Encryption/EncryptAll.php +++ b/core/Command/Encryption/EncryptAll.php @@ -36,24 +36,16 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; class EncryptAll extends Command { - protected IManager $encryptionManager; - protected IAppManager $appManager; - protected IConfig $config; - protected QuestionHelper $questionHelper; protected bool $wasTrashbinEnabled = false; protected bool $wasMaintenanceModeEnabled; public function __construct( - IManager $encryptionManager, - IAppManager $appManager, - IConfig $config, - QuestionHelper $questionHelper + protected IManager $encryptionManager, + protected IAppManager $appManager, + protected IConfig $config, + protected QuestionHelper $questionHelper, ) { parent::__construct(); - $this->appManager = $appManager; - $this->encryptionManager = $encryptionManager; - $this->config = $config; - $this->questionHelper = $questionHelper; } /** diff --git a/core/Command/Encryption/ListModules.php b/core/Command/Encryption/ListModules.php index 88ad987507341..46be88864a794 100644 --- a/core/Command/Encryption/ListModules.php +++ b/core/Command/Encryption/ListModules.php @@ -30,16 +30,11 @@ use Symfony\Component\Console\Output\OutputInterface; class ListModules extends Base { - protected IManager $encryptionManager; - protected IConfig $config; - public function __construct( - IManager $encryptionManager, - IConfig $config + protected IManager $encryptionManager, + protected IConfig $config, ) { parent::__construct(); - $this->encryptionManager = $encryptionManager; - $this->config = $config; } protected function configure() { diff --git a/core/Command/Encryption/MigrateKeyStorage.php b/core/Command/Encryption/MigrateKeyStorage.php index 8d9c7910769cd..0a2a14195f25b 100644 --- a/core/Command/Encryption/MigrateKeyStorage.php +++ b/core/Command/Encryption/MigrateKeyStorage.php @@ -38,20 +38,14 @@ use Symfony\Component\Console\Output\OutputInterface; class MigrateKeyStorage extends Command { - protected View $rootView; - protected IUserManager $userManager; - protected IConfig $config; - protected Util $util; - protected QuestionHelper $questionHelper; - private ICrypto $crypto; - - public function __construct(View $view, IUserManager $userManager, IConfig $config, Util $util, ICrypto $crypto) { + public function __construct( + protected View $rootView, + protected IUserManager $userManager, + protected IConfig $config, + protected Util $util, + private ICrypto $crypto, + ) { parent::__construct(); - $this->rootView = $view; - $this->userManager = $userManager; - $this->config = $config; - $this->util = $util; - $this->crypto = $crypto; } protected function configure() { diff --git a/core/Command/Encryption/SetDefaultModule.php b/core/Command/Encryption/SetDefaultModule.php index b50e004867fef..f410692677883 100644 --- a/core/Command/Encryption/SetDefaultModule.php +++ b/core/Command/Encryption/SetDefaultModule.php @@ -31,16 +31,11 @@ use Symfony\Component\Console\Output\OutputInterface; class SetDefaultModule extends Command { - protected IManager $encryptionManager; - protected IConfig $config; - public function __construct( - IManager $encryptionManager, - IConfig $config + protected IManager $encryptionManager, + protected IConfig $config, ) { parent::__construct(); - $this->encryptionManager = $encryptionManager; - $this->config = $config; } protected function configure() { diff --git a/core/Command/Encryption/ShowKeyStorageRoot.php b/core/Command/Encryption/ShowKeyStorageRoot.php index 1c4f2b4cb4a17..33addebc1be27 100644 --- a/core/Command/Encryption/ShowKeyStorageRoot.php +++ b/core/Command/Encryption/ShowKeyStorageRoot.php @@ -29,11 +29,8 @@ use Symfony\Component\Console\Output\OutputInterface; class ShowKeyStorageRoot extends Command { - protected Util $util; - - public function __construct(Util $util) { + public function __construct(protected Util $util) { parent::__construct(); - $this->util = $util; } protected function configure() { diff --git a/core/Command/Encryption/Status.php b/core/Command/Encryption/Status.php index 34ebabe1b7365..232e897299a7c 100644 --- a/core/Command/Encryption/Status.php +++ b/core/Command/Encryption/Status.php @@ -27,11 +27,8 @@ use Symfony\Component\Console\Output\OutputInterface; class Status extends Base { - protected IManager $encryptionManager; - - public function __construct(IManager $encryptionManager) { + public function __construct(protected IManager $encryptionManager) { parent::__construct(); - $this->encryptionManager = $encryptionManager; } protected function configure() { From 2ace19fc54adff8c86cea8fb039dd9a6883c068d Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Mon, 12 Jun 2023 18:27:35 +0330 Subject: [PATCH 2/5] Fixes php-cs error. Signed-off-by: Faraz Samapoor --- core/Command/Encryption/MigrateKeyStorage.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Command/Encryption/MigrateKeyStorage.php b/core/Command/Encryption/MigrateKeyStorage.php index 0a2a14195f25b..2441aa9cc1a62 100644 --- a/core/Command/Encryption/MigrateKeyStorage.php +++ b/core/Command/Encryption/MigrateKeyStorage.php @@ -33,7 +33,6 @@ use OCP\Security\ICrypto; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; -use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; From bcfbcbb91cd30209d6e7e1278c08fb678f483809 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 13 Jun 2023 11:29:52 +0330 Subject: [PATCH 3/5] Moves single constructor parameters to new lines. Based on: https://github.com/nextcloud/server/pull/38764#discussion_r1227630895 Signed-off-by: Faraz Samapoor --- core/Command/Encryption/Disable.php | 4 +++- core/Command/Encryption/ShowKeyStorageRoot.php | 4 +++- core/Command/Encryption/Status.php | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/core/Command/Encryption/Disable.php b/core/Command/Encryption/Disable.php index e188e6be3442e..4c6e3431f938a 100644 --- a/core/Command/Encryption/Disable.php +++ b/core/Command/Encryption/Disable.php @@ -27,7 +27,9 @@ use Symfony\Component\Console\Output\OutputInterface; class Disable extends Command { - public function __construct(protected IConfig $config) { + public function __construct( + protected IConfig $config, + ) { parent::__construct(); } diff --git a/core/Command/Encryption/ShowKeyStorageRoot.php b/core/Command/Encryption/ShowKeyStorageRoot.php index 33addebc1be27..71b396540fdfc 100644 --- a/core/Command/Encryption/ShowKeyStorageRoot.php +++ b/core/Command/Encryption/ShowKeyStorageRoot.php @@ -29,7 +29,9 @@ use Symfony\Component\Console\Output\OutputInterface; class ShowKeyStorageRoot extends Command { - public function __construct(protected Util $util) { + public function __construct( + protected Util $util, + ) { parent::__construct(); } diff --git a/core/Command/Encryption/Status.php b/core/Command/Encryption/Status.php index 232e897299a7c..691b399203d78 100644 --- a/core/Command/Encryption/Status.php +++ b/core/Command/Encryption/Status.php @@ -27,7 +27,9 @@ use Symfony\Component\Console\Output\OutputInterface; class Status extends Base { - public function __construct(protected IManager $encryptionManager) { + public function __construct( + protected IManager $encryptionManager, + ) { parent::__construct(); } From 9c2abae59c341fa4c947d9575979dac7ca40b2dd Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 11:41:14 +0330 Subject: [PATCH 4/5] Update core/Command/Encryption/EncryptAll.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Faraz Samapoor --- core/Command/Encryption/EncryptAll.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/Encryption/EncryptAll.php b/core/Command/Encryption/EncryptAll.php index 17d3a80394262..cf4ee749791a9 100644 --- a/core/Command/Encryption/EncryptAll.php +++ b/core/Command/Encryption/EncryptAll.php @@ -37,7 +37,7 @@ class EncryptAll extends Command { protected bool $wasTrashbinEnabled = false; - protected bool $wasMaintenanceModeEnabled; + protected bool $wasMaintenanceModeEnabled = false; public function __construct( protected IManager $encryptionManager, From 90035e98c1ef53aa0c9bfaa86112c8bc407a8974 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 11:41:21 +0330 Subject: [PATCH 5/5] Update core/Command/Encryption/DecryptAll.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Faraz Samapoor --- core/Command/Encryption/DecryptAll.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/Command/Encryption/DecryptAll.php b/core/Command/Encryption/DecryptAll.php index 7569605e7751d..137b12141f71d 100644 --- a/core/Command/Encryption/DecryptAll.php +++ b/core/Command/Encryption/DecryptAll.php @@ -41,8 +41,8 @@ use Symfony\Component\Console\Question\ConfirmationQuestion; class DecryptAll extends Command { - protected bool $wasTrashbinEnabled; - protected bool $wasMaintenanceModeEnabled; + protected bool $wasTrashbinEnabled = false; + protected bool $wasMaintenanceModeEnabled = false; public function __construct( protected IManager $encryptionManager,