Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uses PHP8's constructor property promotion in core/Command and / #38775

7 changes: 3 additions & 4 deletions core/Command/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
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() {
Expand Down
11 changes: 4 additions & 7 deletions core/Command/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion core/Command/TwoFactorAuth/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions core/Command/TwoFactorAuth/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +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 {
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() {
Expand Down
14 changes: 8 additions & 6 deletions core/Command/TwoFactorAuth/Disable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
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() {
Expand Down
14 changes: 8 additions & 6 deletions core/Command/TwoFactorAuth/Enable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
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() {
Expand Down
8 changes: 3 additions & 5 deletions core/Command/TwoFactorAuth/Enforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
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() {
Expand Down
15 changes: 8 additions & 7 deletions core/Command/TwoFactorAuth/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
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() {
Expand Down
13 changes: 5 additions & 8 deletions core/Command/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion tests/Core/Command/TwoFactorAuth/CleanupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,15 +37,19 @@ class CleanupTest extends TestCase {
/** @var IRegistry|MockObject */
private $registry;

/** @var IUserManager|MockObject */
private $userManager;

/** @var CommandTester */
private $cmd;

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);
}

Expand Down