Skip to content

Commit

Permalink
* ibexa4.6 : eZ2FABundle Migration [support php>=8.1]
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-larbi-jebari committed Oct 6, 2024
1 parent f27c3ec commit b1048a4
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ final class Remove2FAForUserCommand extends Command
/**
* @var UserProviderInterface
*/
private $userProvider;
private UserProviderInterface $userProvider;

/**
* @var UserRepository
*/
private $userRepository;
private UserRepository $userRepository;

/**
* @required
Expand Down
4 changes: 2 additions & 2 deletions components/2FABundle/bundle/Core/AuthCodeMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ final class AuthCodeMailer implements AuthCodeMailerInterface
private $senderAddress;

public function __construct(
private MailerInterface $mailer,
protected MailerInterface $mailer,
string $senderEmail,
?string $senderName,
private TranslatorInterface $translator
protected TranslatorInterface $translator
) {
$this->senderAddress = new Address($senderEmail, $senderName ?? '');
}
Expand Down
2 changes: 1 addition & 1 deletion components/2FABundle/bundle/Core/BackupCodeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class BackupCodeManager implements BackupCodeManagerInterface
{

public function __construct(private UserRepository $userRepository)
public function __construct(protected UserRepository $userRepository)
{
}

Expand Down
10 changes: 7 additions & 3 deletions components/2FABundle/bundle/Core/EmailCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Novactive\Bundle\eZ2FABundle\Core;

use Exception;
use Novactive\Bundle\eZ2FABundle\Entity\UserEmailAuth;
use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
Expand All @@ -23,9 +24,9 @@ final class EmailCodeGenerator implements CodeGeneratorInterface
{

public function __construct(
private UserRepository $userRepository,
private AuthCodeMailerInterface $mailer,
private int $digits
protected UserRepository $userRepository,
protected AuthCodeMailerInterface $mailer,
protected int $digits
){
}

Expand All @@ -45,6 +46,9 @@ public function reSend(TwoFactorInterface $user): void
$this->mailer->sendAuthCode($user);
}

/**
* @throws Exception
*/
private function generateCode(int $min, int $max): int
{
return random_int($min, $max);
Expand Down
4 changes: 2 additions & 2 deletions components/2FABundle/bundle/Core/QRCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
final class QRCodeGenerator
{
public function __construct(
private GoogleAuthenticator $googleAuthenticator,
private TotpAuthenticator $totpAuthenticator
protected GoogleAuthenticator $googleAuthenticator,
protected TotpAuthenticator $totpAuthenticator
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,34 @@ class SiteAccessAwareAuthenticatorResolver implements SiteAccessAware
/**
* @var SiteAccess|null
*/
private $siteAccess;
private ?SiteAccess $siteAccess;

/**
* @var string
*/
private $method;
private string $method;

/**
* @var array
*/
private $config;
private array $config;

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

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

public function __construct(
private ConfigResolverInterface $configResolver,
private GoogleAuthenticator $googleAuthenticator,
private TotpAuthenticator $totpAuthenticator,
private UserRepository $userRepository,
private bool $backupCodesEnabled
protected ConfigResolverInterface $configResolver,
protected GoogleAuthenticator $googleAuthenticator,
protected TotpAuthenticator $totpAuthenticator,
protected UserRepository $userRepository,
protected bool $backupCodesEnabled
) {
}

Expand Down Expand Up @@ -139,10 +139,7 @@ public function getUserForDecorator(User $user): User
$this->method = 'email';
}

if (
false === $userAuthData ||
('email' !== $this->method && empty($userAuthData["{$this->method}_authentication_secret"]))
) {
if ('email' !== $this->method && empty($userAuthData["{$this->method}_authentication_secret"])) {
return $user;
}

Expand All @@ -158,7 +155,7 @@ public function getUserForDecorator(User $user): User
return $authenticatorEntity;
}

public function getAuthenticator()
public function getAuthenticator(): TotpAuthenticator|GoogleAuthenticator
{
if ('google' === $this->method) {
return $this->googleAuthenticator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ final class SiteAccessAwareQueryExecutor
{

public function __construct(
private Registry $registry,
private RepositoryConfigurationProvider $repositoryConfigurationProvider
protected Registry $registry,
protected RepositoryConfigurationProvider $repositoryConfigurationProvider
) {
}

Expand Down
2 changes: 1 addition & 1 deletion components/2FABundle/bundle/Core/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
final class UserRepository
{
public function __construct(private SiteAccessAwareQueryExecutor $queryExecutor)
public function __construct(protected SiteAccessAwareQueryExecutor $queryExecutor)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class Configuration extends SAConfiguration
{
public const string NAMESPACE = 'nova_ez2fa';
public const NAMESPACE = 'nova_ez2fa';

public function getConfigTreeBuilder(): TreeBuilder
{
Expand Down
2 changes: 1 addition & 1 deletion components/2FABundle/bundle/Entity/BackupCodeAware.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait BackupCodeAware
/**
* @var array
*/
private $backupCodes = [];
private array $backupCodes = [];

public function isBackupCode(string $code): bool
{
Expand Down
4 changes: 2 additions & 2 deletions components/2FABundle/bundle/Entity/UserEmailAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ final class UserEmailAuth extends User implements TwoFactorInterface
/**
* @var string
*/
private $email;
private string $email;

/**
* @var string
*/
private $authCode;
private string $authCode;

public function __construct(APIUser $user, array $roles = [])
{
Expand Down
10 changes: 5 additions & 5 deletions components/2FABundle/bundle/Entity/UserTotpAuthSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ final class UserTotpAuthSecret extends User implements TwoFactorInterface, Backu
/**
* @var string|null
*/
private $secret;
private ?string $secret;

private const string DEFAULT_ALGORITHM = TotpConfiguration::ALGORITHM_SHA1;
private const int DEFAULT_PERIOD = 30;
private const int DEFAULT_DIGITS = 6;
private const DEFAULT_ALGORITHM = TotpConfiguration::ALGORITHM_SHA1;
private const DEFAULT_PERIOD = 30;
private const DEFAULT_DIGITS = 6;

public function __construct(APIUser $user, array $roles = [], private array $config = [])
public function __construct(APIUser $user, array $roles = [], protected array $config = [])
{
parent::__construct($user, $roles);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

final class MenuEventSubscriber implements EventSubscriberInterface
{
public function __construct(private MenuManipulator $menuManipulator, private TranslatorInterface $translator)
public function __construct(protected MenuManipulator $menuManipulator, protected TranslatorInterface $translator)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
final class OnHttpRequestListener
{
public function __construct(
private TokenStorageInterface $tokenStorage,
private SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver,
private RouterInterface $router
protected TokenStorageInterface $tokenStorage,
protected SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver,
protected RouterInterface $router
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

final class TwoFactorAuthenticationEventSubscriber implements EventSubscriberInterface
{
public function __construct(private SiteAccessAwareAuthenticatorResolver $saAwareAuthenticatorResolver)
public function __construct(protected SiteAccessAwareAuthenticatorResolver $saAwareAuthenticatorResolver)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
final class UserEventSubscriber implements EventSubscriberInterface
{

public function __construct(private UserRepository $userRepository)
public function __construct(protected UserRepository $userRepository)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ final class TwoFactorUserProviderDecorator implements UserProviderInterface, API
{

public function __construct(
private UserProviderInterface $provider,
private SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver
protected UserProviderInterface $provider,
protected SiteAccessAwareAuthenticatorResolver $saAuthenticatorResolver
) {
}

Expand Down
2 changes: 1 addition & 1 deletion components/2FABundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"MIT"
],
"require": {
"php": ">=8.3",
"php": ">=8.1",
"scheb/2fa-bundle": "v5.13.2",
"scheb/2fa-google-authenticator": "v5.13.2",
"scheb/2fa-totp": "v5.13.2",
Expand Down

0 comments on commit b1048a4

Please sign in to comment.