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

refactor: PHP8 optimizations #1590

Merged
merged 1 commit into from
Jan 24, 2025
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
13 changes: 4 additions & 9 deletions lib/Activity/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@

class Provider implements IProvider {

/** @var L10nFactory */
private $l10n;

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(L10nFactory $l10n, IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
$this->l10n = $l10n;
public function __construct(
private L10nFactory $l10n,
private IURLGenerator $urlGenerator,
) {
}

public function parse($language, IEvent $event, ?IEvent $previousEvent = null): IEvent {
Expand Down
8 changes: 3 additions & 5 deletions lib/Activity/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@

class Setting implements ISetting {

/** @var IL10N */
private $l10n;

public function __construct(IL10N $l10n) {
$this->l10n = $l10n;
public function __construct(
private IL10N $l10n,
) {
}

public function canChangeMail(): bool {
Expand Down
18 changes: 3 additions & 15 deletions lib/Command/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,13 @@
use Symfony\Component\Console\Style\SymfonyStyle;

class CleanUp extends Command {
/** @var IDBConnection */
private $db;

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

/** @var TotpSecretMapper */
private $totpSecretMapper;

public function __construct(
IDBConnection $db,
IUserManager $userManager,
TotpSecretMapper $totpSecretMapper,
private IDBConnection $db,
private IUserManager $userManager,
private TotpSecretMapper $totpSecretMapper,
) {
parent::__construct();

$this->db = $db;
$this->userManager = $userManager;
$this->totpSecretMapper = $totpSecretMapper;
}

protected function configure(): void {
Expand Down
20 changes: 7 additions & 13 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@

class SettingsController extends ALoginSetupController {

/** @var ITotp */
private $totp;

/** @var IUserSession */
private $userSession;

/** @var Defaults */
private $defaults;

public function __construct(string $appName, IRequest $request, IUserSession $userSession, ITotp $totp, Defaults $defaults) {
public function __construct(
string $appName,
IRequest $request,
private IUserSession $userSession,
private ITotp $totp,
private Defaults $defaults,
) {
parent::__construct($appName, $request);
$this->userSession = $userSession;
$this->totp = $totp;
$this->defaults = $defaults;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions lib/Db/TotpSecretMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace OCA\TwoFactorTOTP\Db;

use Doctrine\DBAL\Statement;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
Expand Down Expand Up @@ -38,8 +37,7 @@ public function getSecret(IUser $user): TotpSecret {
->from($this->getTableName())
->from('twofactor_totp_secrets')
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($user->getUID())));
/** @var Statement $result */
$result = $qb->execute();
$result = $qb->executeQuery();

$row = $result->fetch();
$result->closeCursor();
Expand Down
20 changes: 4 additions & 16 deletions lib/Event/StateChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,17 @@

class StateChanged extends Event {

/** @var IUser */
private $user;

/** @var bool */
private $enabled;

public function __construct(IUser $user, bool $enabled) {
public function __construct(
private IUser $user,
private bool $enabled,
) {
parent::__construct();

$this->user = $user;
$this->enabled = $enabled;
}

/**
* @return IUser
*/
public function getUser(): IUser {
return $this->user;
}

/**
* @return bool
*/
public function isEnabled(): bool {
return $this->enabled;
}
Expand Down
8 changes: 3 additions & 5 deletions lib/Listener/StateChangeActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@
*/
class StateChangeActivity implements IEventListener {

/** @var ActivityManager */
private $activityManager;

public function __construct(ActivityManager $activityManager) {
$this->activityManager = $activityManager;
public function __construct(
private ActivityManager $activityManager,
) {
}

public function handle(Event $event): void {
Expand Down
13 changes: 4 additions & 9 deletions lib/Listener/StateChangeRegistryUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,10 @@
*/
class StateChangeRegistryUpdater implements IEventListener {

/** @var IRegistry */
private $registry;

/** @var TotpProvider */
private $provider;

public function __construct(IRegistry $registry, TotpProvider $provider) {
$this->registry = $registry;
$this->provider = $provider;
public function __construct(
private IRegistry $registry,
private TotpProvider $provider,
) {
}

public function handle(Event $event): void {
Expand Down
13 changes: 4 additions & 9 deletions lib/Listener/UserDeleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,10 @@
*/
class UserDeleted implements IEventListener {

/** @var TotpSecretMapper */
private $totpSecretMapper;

/** @var LoggerInterface */
private $logger;

public function __construct(TotpSecretMapper $totpSecretMapper, LoggerInterface $logger) {
$this->totpSecretMapper = $totpSecretMapper;
$this->logger = $logger;
public function __construct(
private TotpSecretMapper $totpSecretMapper,
private LoggerInterface $logger,
) {
}

public function handle(Event $event): void {
Expand Down
8 changes: 3 additions & 5 deletions lib/Provider/AtLoginProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

class AtLoginProvider implements ILoginSetupProvider {

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(IURLGenerator $urlGenerator) {
$this->urlGenerator = $urlGenerator;
public function __construct(
private IURLGenerator $urlGenerator,
) {
}

public function getBody(): Template {
Expand Down
32 changes: 7 additions & 25 deletions lib/Provider/TotpProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,13 @@

class TotpProvider implements IProvider, IProvidesIcons, IProvidesPersonalSettings, IDeactivatableByAdmin, IActivatableAtLogin {

/** @var ITotp */
private $totp;

/** @var IL10N */
private $l10n;

/** @var IAppContainer */
private $container;

/** @var IInitialState */
private $initialState;

/** @var IURLGenerator */
private $urlGenerator;

public function __construct(ITotp $totp,
IL10N $l10n,
IAppContainer $container,
IInitialState $initialStateService,
IURLGenerator $urlGenerator) {
$this->totp = $totp;
$this->l10n = $l10n;
$this->container = $container;
$this->initialState = $initialStateService;
$this->urlGenerator = $urlGenerator;
public function __construct(
private ITotp $totp,
private IL10N $l10n,
private IAppContainer $container,
private IInitialState $initialState,
private IURLGenerator $urlGenerator,
) {
}

/**
Expand Down
26 changes: 6 additions & 20 deletions lib/Service/Totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,12 @@

class Totp implements ITotp {

/** @var TotpSecretMapper */
private $secretMapper;

/** @var ICrypto */
private $crypto;

/** @var IEventDispatcher */
private $eventDispatcher;

/** @var ISecureRandom */
private $random;

public function __construct(TotpSecretMapper $secretMapper,
ICrypto $crypto,
IEventDispatcher $eventDispatcher,
ISecureRandom $random) {
$this->secretMapper = $secretMapper;
$this->crypto = $crypto;
$this->eventDispatcher = $eventDispatcher;
$this->random = $random;
public function __construct(
private TotpSecretMapper $secretMapper,
private ICrypto $crypto,
private IEventDispatcher $eventDispatcher,
private ISecureRandom $random,
) {
}

public function hasSecret(IUser $user): bool {
Expand Down
Loading