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

[3/3] Refactors /core controllers using constructor property promotion. #38638

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions core/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,13 @@
use Psr\Log\LoggerInterface;

class SearchController extends Controller {
private ISearch $searcher;
private LoggerInterface $logger;

public function __construct(
string $appName,
IRequest $request,
ISearch $search,
LoggerInterface $logger
private ISearch $searcher,
artonge marked this conversation as resolved.
Show resolved Hide resolved
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);

$this->searcher = $search;
$this->logger = $logger;
}

/**
Expand Down
9 changes: 3 additions & 6 deletions core/Controller/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,12 @@
use OCP\ILogger;

class SetupController {
protected Setup $setupHelper;
private string $autoConfigFile;

/**
* @param Setup $setupHelper
*/
public function __construct(Setup $setupHelper) {
public function __construct(
protected Setup $setupHelper,
) {
$this->autoConfigFile = \OC::$configDir.'autoconfig.php';
$this->setupHelper = $setupHelper;
}

public function run(array $post): void {
Expand Down
16 changes: 5 additions & 11 deletions core/Controller/TranslationApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,13 @@
use OCP\Translation\ITranslationManager;

class TranslationApiController extends \OCP\AppFramework\OCSController {
private ITranslationManager $translationManager;
private IL10N $l;

public function __construct(
string $appName,
IRequest $request,
ITranslationManager $translationManager,
IL10N $l,
private ITranslationManager $translationManager,
private IL10N $l10n,
) {
parent::__construct($appName, $request);

$this->translationManager = $translationManager;
$this->l = $l;
}

/**
Expand Down Expand Up @@ -76,11 +70,11 @@ public function translate(string $text, ?string $fromLanguage, string $toLanguag

]);
} catch (PreConditionNotMetException) {
return new DataResponse(['message' => $this->l->t('No translation provider available')], Http::STATUS_PRECONDITION_FAILED);
return new DataResponse(['message' => $this->l10n->t('No translation provider available')], Http::STATUS_PRECONDITION_FAILED);
} catch (InvalidArgumentException) {
return new DataResponse(['message' => $this->l->t('Could not detect language')], Http::STATUS_BAD_REQUEST);
return new DataResponse(['message' => $this->l10n->t('Could not detect language')], Http::STATUS_BAD_REQUEST);
} catch (CouldNotTranslateException $e) {
return new DataResponse(['message' => $this->l->t('Unable to translate'), 'from' => $e->getFrom()], Http::STATUS_BAD_REQUEST);
return new DataResponse(['message' => $this->l10n->t('Unable to translate'), 'from' => $e->getFrom()], Http::STATUS_BAD_REQUEST);
}
}
}
22 changes: 9 additions & 13 deletions core/Controller/TwoFactorChallengeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@
use Psr\Log\LoggerInterface;

class TwoFactorChallengeController extends Controller {
private Manager $twoFactorManager;
private IUserSession $userSession;
private ISession $session;
private LoggerInterface $logger;
private IURLGenerator $urlGenerator;

public function __construct($appName, IRequest $request, Manager $twoFactorManager, IUserSession $userSession,
ISession $session, IURLGenerator $urlGenerator, LoggerInterface $logger) {
public function __construct(
string $appName,
IRequest $request,
private Manager $twoFactorManager,
private IUserSession $userSession,
private ISession $session,
private IURLGenerator $urlGenerator,
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
$this->twoFactorManager = $twoFactorManager;
$this->userSession = $userSession;
$this->session = $session;
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
}

/**
Expand Down
22 changes: 7 additions & 15 deletions core/Controller/UnifiedSearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,14 @@
use Symfony\Component\Routing\Exception\ResourceNotFoundException;

class UnifiedSearchController extends OCSController {
private SearchComposer $composer;
private IUserSession $userSession;
private IRouter $router;
private IURLGenerator $urlGenerator;

public function __construct(IRequest $request,
IUserSession $userSession,
SearchComposer $composer,
IRouter $router,
IURLGenerator $urlGenerator) {
public function __construct(
IRequest $request,
private IUserSession $userSession,
private SearchComposer $composer,
private IRouter $router,
private IURLGenerator $urlGenerator,
) {
parent::__construct('core', $request);

$this->composer = $composer;
$this->userSession = $userSession;
$this->router = $router;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions core/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@
use OCP\IUserManager;

class UserController extends Controller {
protected IUserManager $userManager;

public function __construct($appName,
IRequest $request,
IUserManager $userManager
public function __construct(
string $appName,
IRequest $request,
protected IUserManager $userManager,
) {
parent::__construct($appName, $request);
$this->userManager = $userManager;
}

/**
Expand Down
22 changes: 9 additions & 13 deletions core/Controller/WebAuthnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,16 @@ class WebAuthnController extends Controller {
private const WEBAUTHN_LOGIN = 'webauthn_login';
private const WEBAUTHN_LOGIN_UID = 'webauthn_login_uid';

private Manager $webAuthnManger;
private ISession $session;
private LoggerInterface $logger;
private WebAuthnChain $webAuthnChain;
private UrlGenerator $urlGenerator;

public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain, URLGenerator $urlGenerator) {
public function __construct(
string $appName,
IRequest $request,
private Manager $webAuthnManger,
private ISession $session,
private LoggerInterface $logger,
private WebAuthnChain $webAuthnChain,
private URLGenerator $urlGenerator,
) {
parent::__construct($appName, $request);

$this->webAuthnManger = $webAuthnManger;
$this->session = $session;
$this->logger = $logger;
$this->webAuthnChain = $webAuthnChain;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions core/Controller/WellKnownController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@
use OCP\IRequest;

class WellKnownController extends Controller {
/** @var RequestManager */
private $requestManager;

public function __construct(IRequest $request,
RequestManager $wellKnownManager) {
public function __construct(
IRequest $request,
private RequestManager $requestManager,
artonge marked this conversation as resolved.
Show resolved Hide resolved
) {
parent::__construct('core', $request);
$this->requestManager = $wellKnownManager;
}

/**
Expand Down
26 changes: 5 additions & 21 deletions core/Controller/WhatsNewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,19 @@
use OCP\L10N\IFactory;

class WhatsNewController extends OCSController {
/** @var IConfig */
protected $config;
/** @var IUserSession */
private $userSession;
/** @var ChangesCheck */
private $whatsNewService;
/** @var IFactory */
private $langFactory;
/** @var Defaults */
private $defaults;

public function __construct(
string $appName,
IRequest $request,
CapabilitiesManager $capabilitiesManager,
IUserSession $userSession,
private IUserSession $userSession,
IUserManager $userManager,
Manager $keyManager,
IConfig $config,
ChangesCheck $whatsNewService,
IFactory $langFactory,
Defaults $defaults
private IConfig $config,
private ChangesCheck $whatsNewService,
private IFactory $langFactory,
private Defaults $defaults,
) {
parent::__construct($appName, $request, $capabilitiesManager, $userSession, $userManager, $keyManager);
$this->config = $config;
$this->userSession = $userSession;
$this->whatsNewService = $whatsNewService;
$this->langFactory = $langFactory;
$this->defaults = $defaults;
}

/**
Expand Down
13 changes: 5 additions & 8 deletions core/Controller/WipeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@
use OCP\IRequest;

class WipeController extends Controller {
/** @var RemoteWipe */
private $remoteWipe;

public function __construct(string $appName,
IRequest $request,
RemoteWipe $remoteWipe) {
public function __construct(
string $appName,
IRequest $request,
private RemoteWipe $remoteWipe,
) {
parent::__construct($appName, $request);

$this->remoteWipe = $remoteWipe;
}

/**
Expand Down