From c01129947e9fecd26f10ef588cc0940ff187dc83 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Mon, 12 Jun 2023 19:20:14 +0330 Subject: [PATCH 1/9] Uses PHP8's constructor property promotion. in core/Command and /TwoFactorAuth classes. Signed-off-by: Faraz Samapoor --- core/Command/Check.php | 5 +---- core/Command/Status.php | 11 ++++------- core/Command/TwoFactorAuth/Cleanup.php | 6 +----- core/Command/TwoFactorAuth/Disable.php | 9 ++++----- core/Command/TwoFactorAuth/Enable.php | 9 ++++----- core/Command/TwoFactorAuth/Enforce.php | 6 +----- core/Command/TwoFactorAuth/State.php | 10 ++++------ core/Command/Upgrade.php | 13 +++++-------- 8 files changed, 24 insertions(+), 45 deletions(-) diff --git a/core/Command/Check.php b/core/Command/Check.php index 18c45323f37d..529cb541f6dd 100644 --- a/core/Command/Check.php +++ b/core/Command/Check.php @@ -29,11 +29,8 @@ use Symfony\Component\Console\Output\OutputInterface; class Check extends Base { - private SystemConfig $config; - - public function __construct(SystemConfig $config) { + public function __construct(private SystemConfig $config) { parent::__construct(); - $this->config = $config; } protected function configure() { diff --git a/core/Command/Status.php b/core/Command/Status.php index c59dac557a86..57b831c7eaad 100644 --- a/core/Command/Status.php +++ b/core/Command/Status.php @@ -33,14 +33,11 @@ use Symfony\Component\Console\Output\OutputInterface; class Status extends Base { - private IConfig $config; - private Defaults $themingDefaults; - - public function __construct(IConfig $config, Defaults $themingDefaults) { + public function __construct( + private IConfig $config, + private Defaults $themingDefaults, + ) { parent::__construct('status'); - - $this->config = $config; - $this->themingDefaults = $themingDefaults; } protected function configure() { diff --git a/core/Command/TwoFactorAuth/Cleanup.php b/core/Command/TwoFactorAuth/Cleanup.php index 7d3fc3c33f74..125a7b01f4af 100644 --- a/core/Command/TwoFactorAuth/Cleanup.php +++ b/core/Command/TwoFactorAuth/Cleanup.php @@ -32,12 +32,8 @@ use Symfony\Component\Console\Output\OutputInterface; class Cleanup extends Base { - private IRegistry $registry; - - public function __construct(IRegistry $registry) { + public function __construct(private IRegistry $registry) { parent::__construct(); - - $this->registry = $registry; } protected function configure() { diff --git a/core/Command/TwoFactorAuth/Disable.php b/core/Command/TwoFactorAuth/Disable.php index 54e4b138a0ae..1de4d711e0e9 100644 --- a/core/Command/TwoFactorAuth/Disable.php +++ b/core/Command/TwoFactorAuth/Disable.php @@ -29,12 +29,11 @@ use Symfony\Component\Console\Output\OutputInterface; class Disable extends Base { - private ProviderManager $manager; - - public function __construct(ProviderManager $manager, IUserManager $userManager) { + public function __construct( + private ProviderManager $manager, + protected IUserManager $userManager, + ) { parent::__construct('twofactorauth:disable'); - $this->manager = $manager; - $this->userManager = $userManager; } protected function configure() { diff --git a/core/Command/TwoFactorAuth/Enable.php b/core/Command/TwoFactorAuth/Enable.php index 67c1778399de..38d6894b4624 100644 --- a/core/Command/TwoFactorAuth/Enable.php +++ b/core/Command/TwoFactorAuth/Enable.php @@ -29,12 +29,11 @@ use Symfony\Component\Console\Output\OutputInterface; class Enable extends Base { - private ProviderManager $manager; - - public function __construct(ProviderManager $manager, IUserManager $userManager) { + public function __construct( + private ProviderManager $manager, + protected IUserManager $userManager, + ) { parent::__construct('twofactorauth:enable'); - $this->manager = $manager; - $this->userManager = $userManager; } protected function configure() { diff --git a/core/Command/TwoFactorAuth/Enforce.php b/core/Command/TwoFactorAuth/Enforce.php index d8fa41e2e95c..b2a05a531fb5 100644 --- a/core/Command/TwoFactorAuth/Enforce.php +++ b/core/Command/TwoFactorAuth/Enforce.php @@ -35,12 +35,8 @@ use Symfony\Component\Console\Output\OutputInterface; class Enforce extends Command { - private MandatoryTwoFactor $mandatoryTwoFactor; - - public function __construct(MandatoryTwoFactor $mandatoryTwoFactor) { + public function __construct(private MandatoryTwoFactor $mandatoryTwoFactor) { parent::__construct(); - - $this->mandatoryTwoFactor = $mandatoryTwoFactor; } protected function configure() { diff --git a/core/Command/TwoFactorAuth/State.php b/core/Command/TwoFactorAuth/State.php index 4694c76b4081..d4e930b7c9d2 100644 --- a/core/Command/TwoFactorAuth/State.php +++ b/core/Command/TwoFactorAuth/State.php @@ -33,13 +33,11 @@ use Symfony\Component\Console\Output\OutputInterface; class State extends Base { - private IRegistry $registry; - - public function __construct(IRegistry $registry, IUserManager $userManager) { + public function __construct( + private IRegistry $registry, + protected IUserManager $userManager, + ) { parent::__construct('twofactorauth:state'); - - $this->registry = $registry; - $this->userManager = $userManager; } protected function configure() { diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index e929dc22bc8c..078f994d0516 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -62,15 +62,12 @@ class Upgrade extends Command { public const ERROR_INVALID_ARGUMENTS = 4; public const ERROR_FAILURE = 5; - private IConfig $config; - private LoggerInterface $logger; - private Installer $installer; - - public function __construct(IConfig $config, LoggerInterface $logger, Installer $installer) { + public function __construct( + private IConfig $config, + private LoggerInterface $logger, + private Installer $installer, + ) { parent::__construct(); - $this->config = $config; - $this->logger = $logger; - $this->installer = $installer; } protected function configure() { From 0db057262685c7a64c690de7a0e162dd52ccea55 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 15:22:22 +0330 Subject: [PATCH 2/9] Adds constructor to the Based class. Based on: https://github.com/nextcloud/server/pull/38775#discussion_r1227641788 Signed-off-by: Faraz Samapoor --- core/Command/TwoFactorAuth/Base.php | 7 ++++++- core/Command/TwoFactorAuth/Cleanup.php | 11 +++++++++-- core/Command/TwoFactorAuth/Disable.php | 5 ++++- core/Command/TwoFactorAuth/Enable.php | 5 ++++- core/Command/TwoFactorAuth/State.php | 5 ++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/core/Command/TwoFactorAuth/Base.php b/core/Command/TwoFactorAuth/Base.php index 27bd381d9511..a36cb2af3742 100644 --- a/core/Command/TwoFactorAuth/Base.php +++ b/core/Command/TwoFactorAuth/Base.php @@ -30,7 +30,12 @@ use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; class Base extends \OC\Core\Command\Base { - protected IUserManager $userManager; + public function __construct( + ?string $name, + protected IUserManager $userManager, + ) { + parent::__construct($name); + } /** * Return possible values for the named option diff --git a/core/Command/TwoFactorAuth/Cleanup.php b/core/Command/TwoFactorAuth/Cleanup.php index 125a7b01f4af..e70c93bcc1c9 100644 --- a/core/Command/TwoFactorAuth/Cleanup.php +++ b/core/Command/TwoFactorAuth/Cleanup.php @@ -27,13 +27,20 @@ namespace OC\Core\Command\TwoFactorAuth; use OCP\Authentication\TwoFactorAuth\IRegistry; +use OCP\IUserManager; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class Cleanup extends Base { - public function __construct(private IRegistry $registry) { - parent::__construct(); + public function __construct( + private IRegistry $registry, + protected IUserManager $userManager, + ) { + parent::__construct( + null, + $userManager, + ); } protected function configure() { diff --git a/core/Command/TwoFactorAuth/Disable.php b/core/Command/TwoFactorAuth/Disable.php index 1de4d711e0e9..08f1422d458f 100644 --- a/core/Command/TwoFactorAuth/Disable.php +++ b/core/Command/TwoFactorAuth/Disable.php @@ -33,7 +33,10 @@ public function __construct( private ProviderManager $manager, protected IUserManager $userManager, ) { - parent::__construct('twofactorauth:disable'); + parent::__construct( + 'twofactorauth:disable', + $userManager, + ); } protected function configure() { diff --git a/core/Command/TwoFactorAuth/Enable.php b/core/Command/TwoFactorAuth/Enable.php index 38d6894b4624..2138fcd6dbbd 100644 --- a/core/Command/TwoFactorAuth/Enable.php +++ b/core/Command/TwoFactorAuth/Enable.php @@ -33,7 +33,10 @@ public function __construct( private ProviderManager $manager, protected IUserManager $userManager, ) { - parent::__construct('twofactorauth:enable'); + parent::__construct( + 'twofactorauth:enable', + $userManager, + ); } protected function configure() { diff --git a/core/Command/TwoFactorAuth/State.php b/core/Command/TwoFactorAuth/State.php index d4e930b7c9d2..acd35638ee6a 100644 --- a/core/Command/TwoFactorAuth/State.php +++ b/core/Command/TwoFactorAuth/State.php @@ -37,7 +37,10 @@ public function __construct( private IRegistry $registry, protected IUserManager $userManager, ) { - parent::__construct('twofactorauth:state'); + parent::__construct( + 'twofactorauth:state', + $userManager, + ); } protected function configure() { From cb8850dc8fdf57ad1d87ee4b8142060c7c340944 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 19:00:21 +0330 Subject: [PATCH 3/9] Update core/Command/Check.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/Check.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/Command/Check.php b/core/Command/Check.php index 529cb541f6dd..478486b7dee2 100644 --- a/core/Command/Check.php +++ b/core/Command/Check.php @@ -29,7 +29,9 @@ use Symfony\Component\Console\Output\OutputInterface; class Check extends Base { - public function __construct(private SystemConfig $config) { + public function __construct( + private SystemConfig $config, + ) { parent::__construct(); } From 116b8c68a6fd5146797c5f756e2ee84131d3e64c Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 19:00:46 +0330 Subject: [PATCH 4/9] Update core/Command/TwoFactorAuth/Enforce.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/TwoFactorAuth/Enforce.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/Command/TwoFactorAuth/Enforce.php b/core/Command/TwoFactorAuth/Enforce.php index b2a05a531fb5..e747ff99d592 100644 --- a/core/Command/TwoFactorAuth/Enforce.php +++ b/core/Command/TwoFactorAuth/Enforce.php @@ -35,7 +35,9 @@ use Symfony\Component\Console\Output\OutputInterface; class Enforce extends Command { - public function __construct(private MandatoryTwoFactor $mandatoryTwoFactor) { + public function __construct( + private MandatoryTwoFactor $mandatoryTwoFactor, + ) { parent::__construct(); } From 9bd9c09aaeb24d06d439a19d6996b0de5a3e3519 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 19:04:43 +0330 Subject: [PATCH 5/9] Update core/Command/TwoFactorAuth/State.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/TwoFactorAuth/State.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/TwoFactorAuth/State.php b/core/Command/TwoFactorAuth/State.php index acd35638ee6a..ddae1fe963aa 100644 --- a/core/Command/TwoFactorAuth/State.php +++ b/core/Command/TwoFactorAuth/State.php @@ -35,7 +35,7 @@ class State extends Base { public function __construct( private IRegistry $registry, - protected IUserManager $userManager, + IUserManager $userManager, ) { parent::__construct( 'twofactorauth:state', From 34e8887ddb7062749af5fb97811d107a9e4b9d24 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 19:04:56 +0330 Subject: [PATCH 6/9] Update core/Command/TwoFactorAuth/Disable.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/TwoFactorAuth/Disable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/TwoFactorAuth/Disable.php b/core/Command/TwoFactorAuth/Disable.php index 08f1422d458f..a593993128f9 100644 --- a/core/Command/TwoFactorAuth/Disable.php +++ b/core/Command/TwoFactorAuth/Disable.php @@ -31,7 +31,7 @@ class Disable extends Base { public function __construct( private ProviderManager $manager, - protected IUserManager $userManager, + IUserManager $userManager, ) { parent::__construct( 'twofactorauth:disable', From 6e33efa5432601b6bd3ca5307619112b10953a4d Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 19:05:07 +0330 Subject: [PATCH 7/9] Update core/Command/TwoFactorAuth/Enable.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/TwoFactorAuth/Enable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/TwoFactorAuth/Enable.php b/core/Command/TwoFactorAuth/Enable.php index 2138fcd6dbbd..b0d80c43a611 100644 --- a/core/Command/TwoFactorAuth/Enable.php +++ b/core/Command/TwoFactorAuth/Enable.php @@ -31,7 +31,7 @@ class Enable extends Base { public function __construct( private ProviderManager $manager, - protected IUserManager $userManager, + IUserManager $userManager, ) { parent::__construct( 'twofactorauth:enable', From faaa8cc4e12d8731e53530538ac84247dd03def1 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 20 Jun 2023 19:07:13 +0330 Subject: [PATCH 8/9] Update core/Command/TwoFactorAuth/Cleanup.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/TwoFactorAuth/Cleanup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Command/TwoFactorAuth/Cleanup.php b/core/Command/TwoFactorAuth/Cleanup.php index e70c93bcc1c9..1b2c6e226324 100644 --- a/core/Command/TwoFactorAuth/Cleanup.php +++ b/core/Command/TwoFactorAuth/Cleanup.php @@ -35,7 +35,7 @@ class Cleanup extends Base { public function __construct( private IRegistry $registry, - protected IUserManager $userManager, + IUserManager $userManager, ) { parent::__construct( null, From fd0e2f711aef29c22f59566f151581424b79e514 Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Fri, 23 Jun 2023 21:20:23 +0330 Subject: [PATCH 9/9] Fixes testcase error. Signed-off-by: Faraz Samapoor --- tests/Core/Command/TwoFactorAuth/CleanupTest.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/Core/Command/TwoFactorAuth/CleanupTest.php b/tests/Core/Command/TwoFactorAuth/CleanupTest.php index b23e9c9b4c48..23461ebd7842 100644 --- a/tests/Core/Command/TwoFactorAuth/CleanupTest.php +++ b/tests/Core/Command/TwoFactorAuth/CleanupTest.php @@ -28,6 +28,7 @@ use OC\Core\Command\TwoFactorAuth\Cleanup; use OCP\Authentication\TwoFactorAuth\IRegistry; +use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Console\Tester\CommandTester; use Test\TestCase; @@ -36,6 +37,9 @@ class CleanupTest extends TestCase { /** @var IRegistry|MockObject */ private $registry; + /** @var IUserManager|MockObject */ + private $userManager; + /** @var CommandTester */ private $cmd; @@ -43,8 +47,9 @@ protected function setUp(): void { parent::setUp(); $this->registry = $this->createMock(IRegistry::class); + $this->userManager = $this->createMock(IUserManager::class); - $cmd = new Cleanup($this->registry); + $cmd = new Cleanup($this->registry, $this->userManager); $this->cmd = new CommandTester($cmd); }