Browse Source
Merge pull request #38775 from fsamapoor/constructor_property_promotion_in_core_command_part9
Uses PHP8's constructor property promotion in core/Command and /
pull/39005/head
Côme Chilliet
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with
60 additions and
51 deletions
-
core/Command/Check.php
-
core/Command/Status.php
-
core/Command/TwoFactorAuth/Base.php
-
core/Command/TwoFactorAuth/Cleanup.php
-
core/Command/TwoFactorAuth/Disable.php
-
core/Command/TwoFactorAuth/Enable.php
-
core/Command/TwoFactorAuth/Enforce.php
-
core/Command/TwoFactorAuth/State.php
-
core/Command/Upgrade.php
-
tests/Core/Command/TwoFactorAuth/CleanupTest.php
|
|
|
@ -29,11 +29,10 @@ use Symfony\Component\Console\Input\InputInterface; |
|
|
|
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() { |
|
|
|
|
|
|
|
@ -33,14 +33,11 @@ use Symfony\Component\Console\Input\InputOption; |
|
|
|
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() { |
|
|
|
|
|
|
|
@ -30,7 +30,12 @@ use OCP\IUserManager; |
|
|
|
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 |
|
|
|
|
|
|
|
@ -27,17 +27,20 @@ declare(strict_types=1); |
|
|
|
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 { |
|
|
|
private IRegistry $registry; |
|
|
|
|
|
|
|
public function __construct(IRegistry $registry) { |
|
|
|
parent::__construct(); |
|
|
|
|
|
|
|
$this->registry = $registry; |
|
|
|
public function __construct( |
|
|
|
private IRegistry $registry, |
|
|
|
IUserManager $userManager, |
|
|
|
) { |
|
|
|
parent::__construct( |
|
|
|
null, |
|
|
|
$userManager, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected function configure() { |
|
|
|
|
|
|
|
@ -29,12 +29,14 @@ use Symfony\Component\Console\Input\InputInterface; |
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
|
class Disable extends Base { |
|
|
|
private ProviderManager $manager; |
|
|
|
|
|
|
|
public function __construct(ProviderManager $manager, IUserManager $userManager) { |
|
|
|
parent::__construct('twofactorauth:disable'); |
|
|
|
$this->manager = $manager; |
|
|
|
$this->userManager = $userManager; |
|
|
|
public function __construct( |
|
|
|
private ProviderManager $manager, |
|
|
|
IUserManager $userManager, |
|
|
|
) { |
|
|
|
parent::__construct( |
|
|
|
'twofactorauth:disable', |
|
|
|
$userManager, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected function configure() { |
|
|
|
|
|
|
|
@ -29,12 +29,14 @@ use Symfony\Component\Console\Input\InputInterface; |
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
|
class Enable extends Base { |
|
|
|
private ProviderManager $manager; |
|
|
|
|
|
|
|
public function __construct(ProviderManager $manager, IUserManager $userManager) { |
|
|
|
parent::__construct('twofactorauth:enable'); |
|
|
|
$this->manager = $manager; |
|
|
|
$this->userManager = $userManager; |
|
|
|
public function __construct( |
|
|
|
private ProviderManager $manager, |
|
|
|
IUserManager $userManager, |
|
|
|
) { |
|
|
|
parent::__construct( |
|
|
|
'twofactorauth:enable', |
|
|
|
$userManager, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected function configure() { |
|
|
|
|
|
|
|
@ -35,12 +35,10 @@ use Symfony\Component\Console\Input\InputOption; |
|
|
|
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() { |
|
|
|
|
|
|
|
@ -33,13 +33,14 @@ use Symfony\Component\Console\Input\InputInterface; |
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
|
|
|
class State extends Base { |
|
|
|
private IRegistry $registry; |
|
|
|
|
|
|
|
public function __construct(IRegistry $registry, IUserManager $userManager) { |
|
|
|
parent::__construct('twofactorauth:state'); |
|
|
|
|
|
|
|
$this->registry = $registry; |
|
|
|
$this->userManager = $userManager; |
|
|
|
public function __construct( |
|
|
|
private IRegistry $registry, |
|
|
|
IUserManager $userManager, |
|
|
|
) { |
|
|
|
parent::__construct( |
|
|
|
'twofactorauth:state', |
|
|
|
$userManager, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
protected function configure() { |
|
|
|
|
|
|
|
@ -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() { |
|
|
|
|
|
|
|
@ -28,6 +28,7 @@ namespace Core\Command\TwoFactorAuth; |
|
|
|
|
|
|
|
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 @@ class CleanupTest extends TestCase { |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
|