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

DevKit updates for 5.x branch #1596

Merged
merged 5 commits into from
Mar 8, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2, composer-normalize:2
env:
8 changes: 4 additions & 4 deletions .github/workflows/qa.yaml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2
extensions: mongodb
@@ -55,7 +55,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2
extensions: mongodb
@@ -67,7 +67,7 @@ jobs:
composer-options: --prefer-dist --prefer-stable

- name: Psalm
run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.1
run: vendor/bin/psalm --no-progress --show-info=false --stats --output-format=github --threads=$(nproc) --shepherd --php-version=8.2

rector:
name: Rector
@@ -81,7 +81,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2
extensions: mongodb
8 changes: 4 additions & 4 deletions .github/workflows/symfony-lint.yaml
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2

@@ -54,7 +54,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2

@@ -79,7 +79,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2

@@ -104,7 +104,7 @@ jobs:
- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none
tools: composer:v2

19 changes: 4 additions & 15 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@ jobs:
strategy:
matrix:
php-version:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
@@ -45,31 +44,21 @@ jobs:
symfony-require: ['']
variant: [normal]
include:
- php-version: '7.4'
- php-version: '8.0'
dependencies: lowest
allowed-to-fail: false
variant: normal
- php-version: '8.1'
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 4.4.*
variant: symfony/symfony:"4.4.*"
- php-version: '8.1'
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 5.4.*
variant: symfony/symfony:"5.4.*"
- php-version: '8.1'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.0.*
variant: symfony/symfony:"6.0.*"
- php-version: '8.1'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.1.*
variant: symfony/symfony:"6.1.*"
- php-version: '8.1'
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 6.2.*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -117,7 +117,7 @@ phpstan:
.PHONY: phpstan

psalm:
vendor/bin/psalm --php-version=8.1
vendor/bin/psalm --php-version=8.2
.PHONY: psalm

rector:
44 changes: 22 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
@@ -20,31 +20,31 @@
],
"homepage": "https://docs.sonata-project.org/projects/SonataUserBundle",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.0",
"doctrine/collections": "^1.6",
"doctrine/common": "^3.1",
"doctrine/persistence": "^2.1 || ^3.0",
"sonata-project/doctrine-extensions": "^1.13 || ^2.0",
"sonata-project/form-extensions": "^1.4",
"sonata-project/twig-extensions": "^1.3 || ^2.0",
"symfony/config": "^4.4.11 || ^5.4 || ^6.0",
"symfony/console": "^4.4 || ^5.4 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.0",
"symfony/form": "^4.4.20 || ^5.4 || ^6.0",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0",
"symfony/http-foundation": "^4.4 || ^5.4 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.0",
"symfony/mailer": "^4.4 || ^5.4 || ^6.0",
"symfony/mime": "^4.4.10 || ^5.4 || ^6.0",
"symfony/options-resolver": "^4.4 || ^5.4 || ^6.0",
"symfony/routing": "^4.4 || ^5.4 || ^6.0",
"symfony/config": "^4.4.11 || ^5.4 || ^6.2",
"symfony/console": "^4.4 || ^5.4 || ^6.2",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2",
"symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.2",
"symfony/form": "^4.4.20 || ^5.4 || ^6.2",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2",
"symfony/http-foundation": "^4.4 || ^5.4 || ^6.2",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.2",
"symfony/mailer": "^4.4 || ^5.4 || ^6.2",
"symfony/mime": "^4.4.10 || ^5.4 || ^6.2",
"symfony/options-resolver": "^4.4 || ^5.4 || ^6.2",
"symfony/routing": "^4.4 || ^5.4 || ^6.2",
"symfony/security-acl": "^3.0",
"symfony/security-core": "^4.4.23 || ^5.4 || ^6.0",
"symfony/security-csrf": "^4.4 || ^5.4 || ^6.0",
"symfony/translation": "^4.4 || ^5.4 || ^6.0",
"symfony/security-core": "^4.4.23 || ^5.4 || ^6.2",
"symfony/security-csrf": "^4.4 || ^5.4 || ^6.2",
"symfony/translation": "^4.4 || ^5.4 || ^6.2",
"symfony/translation-contracts": "^1.1 || ^2.5 || ^3.0",
"symfony/validator": "^4.4 || ^5.4 || ^6.0",
"symfony/validator": "^4.4 || ^5.4 || ^6.2",
"twig/twig": "^2.14 || ^3.0"
},
"require-dev": {
@@ -69,11 +69,11 @@
"sonata-project/admin-bundle": "^4.20",
"sonata-project/block-bundle": "^4.11",
"sonata-project/doctrine-orm-admin-bundle": "^4.0",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.0",
"symfony/console": "^4.4 || ^5.4 || ^6.0",
"symfony/filesystem": "^4.4 || ^5.4 || ^6.0",
"symfony/intl": "^4.4 || ^5.4 || ^6.0",
"symfony/phpunit-bridge": "^6.1",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.2",
"symfony/console": "^4.4 || ^5.4 || ^6.2",
"symfony/filesystem": "^4.4 || ^5.4 || ^6.2",
"symfony/intl": "^4.4 || ^5.4 || ^6.2",
"symfony/phpunit-bridge": "^6.2",
"vimeo/psalm": "^4.9.2"
},
"conflict": {
13 changes: 13 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.30.0@d0bc6e25d89f649e4f36a534f330f8bb4643dd69">
<file src="src/Document/UserManager.php">
<UndefinedDocblockClass occurrences="1">
<code>UserPasswordEncoderInterface|UserPasswordHasherInterface</code>
</UndefinedDocblockClass>
</file>
<file src="src/Entity/UserManager.php">
<UndefinedDocblockClass occurrences="1">
<code>UserPasswordEncoderInterface|UserPasswordHasherInterface</code>
</UndefinedDocblockClass>
</file>
</files>
2 changes: 1 addition & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
<psalm xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" errorLevel="2" findUnusedPsalmSuppress="true" resolveFromConfigFile="true" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" errorBaseline="psalm-baseline.xml">
<projectFiles>
<directory name="src"/>
<directory name="tests"/>
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_74,
LevelSetList::UP_TO_PHP_80,
]);

$rectorConfig->importNames();
25 changes: 5 additions & 20 deletions src/Action/CheckEmailAction.php
Original file line number Diff line number Diff line change
@@ -23,28 +23,13 @@

final class CheckEmailAction
{
private Environment $twig;

private UrlGeneratorInterface $urlGenerator;

private Pool $adminPool;

private TemplateRegistryInterface $templateRegistry;

private int $tokenTtl;

public function __construct(
Environment $twig,
UrlGeneratorInterface $urlGenerator,
Pool $adminPool,
TemplateRegistryInterface $templateRegistry,
int $tokenTtl
private Environment $twig,
private UrlGeneratorInterface $urlGenerator,
private Pool $adminPool,
private TemplateRegistryInterface $templateRegistry,
private int $tokenTtl
) {
$this->twig = $twig;
$this->urlGenerator = $urlGenerator;
$this->adminPool = $adminPool;
$this->templateRegistry = $templateRegistry;
$this->tokenTtl = $tokenTtl;
}

public function __invoke(Request $request): Response
40 changes: 8 additions & 32 deletions src/Action/LoginAction.php
Original file line number Diff line number Diff line change
@@ -28,40 +28,16 @@

final class LoginAction
{
private Environment $twig;

private UrlGeneratorInterface $urlGenerator;

private AuthenticationUtils $authenticationUtils;

private Pool $adminPool;

private TemplateRegistryInterface $templateRegistry;

private TokenStorageInterface $tokenStorage;

private TranslatorInterface $translator;

private ?CsrfTokenManagerInterface $csrfTokenManager;

public function __construct(
Environment $twig,
UrlGeneratorInterface $urlGenerator,
AuthenticationUtils $authenticationUtils,
Pool $adminPool,
TemplateRegistryInterface $templateRegistry,
TokenStorageInterface $tokenStorage,
TranslatorInterface $translator,
?CsrfTokenManagerInterface $csrfTokenManager = null
private Environment $twig,
private UrlGeneratorInterface $urlGenerator,
private AuthenticationUtils $authenticationUtils,
private Pool $adminPool,
private TemplateRegistryInterface $templateRegistry,
private TokenStorageInterface $tokenStorage,
private TranslatorInterface $translator,
private ?CsrfTokenManagerInterface $csrfTokenManager = null
) {
$this->twig = $twig;
$this->urlGenerator = $urlGenerator;
$this->authenticationUtils = $authenticationUtils;
$this->adminPool = $adminPool;
$this->templateRegistry = $templateRegistry;
$this->tokenStorage = $tokenStorage;
$this->translator = $translator;
$this->csrfTokenManager = $csrfTokenManager;
}

public function __invoke(Request $request): Response
50 changes: 10 additions & 40 deletions src/Action/RequestAction.php
Original file line number Diff line number Diff line change
@@ -29,48 +29,18 @@

final class RequestAction
{
private Environment $twig;

private UrlGeneratorInterface $urlGenerator;

private AuthorizationCheckerInterface $authorizationChecker;

private Pool $adminPool;

private TemplateRegistryInterface $templateRegistry;

private FormFactoryInterface $formFactory;

private UserManagerInterface $userManager;

private MailerInterface $mailer;

private TokenGeneratorInterface $tokenGenerator;

private int $retryTtl;

public function __construct(
Environment $twig,
UrlGeneratorInterface $urlGenerator,
AuthorizationCheckerInterface $authorizationChecker,
Pool $adminPool,
TemplateRegistryInterface $templateRegistry,
FormFactoryInterface $formFactory,
UserManagerInterface $userManager,
MailerInterface $mailer,
TokenGeneratorInterface $tokenGenerator,
int $retryTtl
private Environment $twig,
private UrlGeneratorInterface $urlGenerator,
private AuthorizationCheckerInterface $authorizationChecker,
private Pool $adminPool,
private TemplateRegistryInterface $templateRegistry,
private FormFactoryInterface $formFactory,
private UserManagerInterface $userManager,
private MailerInterface $mailer,
private TokenGeneratorInterface $tokenGenerator,
private int $retryTtl
) {
$this->twig = $twig;
$this->urlGenerator = $urlGenerator;
$this->authorizationChecker = $authorizationChecker;
$this->adminPool = $adminPool;
$this->templateRegistry = $templateRegistry;
$this->formFactory = $formFactory;
$this->userManager = $userManager;
$this->mailer = $mailer;
$this->tokenGenerator = $tokenGenerator;
$this->retryTtl = $retryTtl;
}

public function __invoke(Request $request): Response
45 changes: 9 additions & 36 deletions src/Action/ResetAction.php
Original file line number Diff line number Diff line change
@@ -29,44 +29,17 @@

final class ResetAction
{
private Environment $twig;

private UrlGeneratorInterface $urlGenerator;

private AuthorizationCheckerInterface $authorizationChecker;

private Pool $adminPool;

private TemplateRegistryInterface $templateRegistry;

private FormFactoryInterface $formFactory;

private UserManagerInterface $userManager;

private TranslatorInterface $translator;

private int $tokenTtl;

public function __construct(
Environment $twig,
UrlGeneratorInterface $urlGenerator,
AuthorizationCheckerInterface $authorizationChecker,
Pool $adminPool,
TemplateRegistryInterface $templateRegistry,
FormFactoryInterface $formFactory,
UserManagerInterface $userManager,
TranslatorInterface $translator,
int $tokenTtl
private Environment $twig,
private UrlGeneratorInterface $urlGenerator,
private AuthorizationCheckerInterface $authorizationChecker,
private Pool $adminPool,
private TemplateRegistryInterface $templateRegistry,
private FormFactoryInterface $formFactory,
private UserManagerInterface $userManager,
private TranslatorInterface $translator,
private int $tokenTtl
) {
$this->twig = $twig;
$this->urlGenerator = $urlGenerator;
$this->authorizationChecker = $authorizationChecker;
$this->adminPool = $adminPool;
$this->templateRegistry = $templateRegistry;
$this->formFactory = $formFactory;
$this->userManager = $userManager;
$this->translator = $translator;
$this->tokenTtl = $tokenTtl;
}

public function __invoke(Request $request, string $token): Response
4 changes: 1 addition & 3 deletions src/Admin/Model/UserAdmin.php
Original file line number Diff line number Diff line change
@@ -29,13 +29,11 @@
*/
class UserAdmin extends AbstractAdmin
{
protected UserManagerInterface $userManager;
protected $classnameLabel = 'user';

public function __construct(UserManagerInterface $userManager)
public function __construct(protected UserManagerInterface $userManager)
{
parent::__construct();
$this->userManager = $userManager;
}

protected function preUpdate(object $object): void
6 changes: 1 addition & 5 deletions src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
@@ -30,13 +30,9 @@ final class ActivateUserCommand extends Command
protected static $defaultName = 'sonata:user:activate';
protected static $defaultDescription = 'Activate a user';

private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();

$this->userManager = $userManager;
}

protected function configure(): void
6 changes: 1 addition & 5 deletions src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
@@ -30,13 +30,9 @@ final class ChangePasswordCommand extends Command
protected static $defaultName = 'sonata:user:change-password';
protected static $defaultDescription = 'Change the password of a user';

private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();

$this->userManager = $userManager;
}

protected function configure(): void
6 changes: 1 addition & 5 deletions src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
@@ -31,13 +31,9 @@ final class CreateUserCommand extends Command
protected static $defaultName = 'sonata:user:create';
protected static $defaultDescription = 'Create a user';

private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();

$this->userManager = $userManager;
}

protected function configure(): void
6 changes: 1 addition & 5 deletions src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
@@ -30,13 +30,9 @@ final class DeactivateUserCommand extends Command
protected static $defaultName = 'sonata:user:deactivate';
protected static $defaultDescription = 'Deactivate a user';

private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();

$this->userManager = $userManager;
}

protected function configure(): void
6 changes: 1 addition & 5 deletions src/Command/DemoteUserCommand.php
Original file line number Diff line number Diff line change
@@ -31,13 +31,9 @@ final class DemoteUserCommand extends Command
protected static $defaultName = 'sonata:user:demote';
protected static $defaultDescription = 'Demotes a user by removing a role';

private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();

$this->userManager = $userManager;
}

protected function configure(): void
6 changes: 1 addition & 5 deletions src/Command/PromoteUserCommand.php
Original file line number Diff line number Diff line change
@@ -31,13 +31,9 @@ final class PromoteUserCommand extends Command
protected static $defaultName = 'sonata:user:promote';
protected static $defaultDescription = 'Promotes a user by adding a role';

private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
parent::__construct();

$this->userManager = $userManager;
}

protected function configure(): void
21 changes: 2 additions & 19 deletions src/Document/UserManager.php
Original file line number Diff line number Diff line change
@@ -28,38 +28,21 @@
*/
final class UserManager extends BaseDocumentManager implements UserManagerInterface
{
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater;

/**
* TODO: Simplify this once support for Symfony 4.4 is dropped.
*
* @psalm-suppress UndefinedDocblockClass
* @phpstan-ignore-next-line
*
* @var UserPasswordEncoderInterface|UserPasswordHasherInterface
*/
private object $userPasswordHasher;

/**
* TODO: Simplify this once support for Symfony 4.4 is dropped.
*
* @psalm-suppress UndefinedDocblockClass
*
* @param UserPasswordEncoderInterface|UserPasswordHasherInterface $userPasswordHasher
*
* @phpstan-param class-string<UserInterface> $class
*/
public function __construct(
string $class,
ManagerRegistry $registry,
CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
// @phpstan-ignore-next-line
object $userPasswordHasher
private object $userPasswordHasher
) {
parent::__construct($class, $registry);

$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
$this->userPasswordHasher = $userPasswordHasher;
}

/**
21 changes: 2 additions & 19 deletions src/Entity/UserManager.php
Original file line number Diff line number Diff line change
@@ -28,38 +28,21 @@
*/
final class UserManager extends BaseEntityManager implements UserManagerInterface
{
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater;

/**
* TODO: Simplify this once support for Symfony 4.4 is dropped.
*
* @psalm-suppress UndefinedDocblockClass
* @phpstan-ignore-next-line
*
* @var UserPasswordEncoderInterface|UserPasswordHasherInterface
*/
private object $userPasswordHasher;

/**
* TODO: Simplify this once support for Symfony 4.4 is dropped.
*
* @psalm-suppress UndefinedDocblockClass
*
* @param UserPasswordEncoderInterface|UserPasswordHasherInterface $userPasswordHasher
*
* @phpstan-param class-string<UserInterface> $class
*/
public function __construct(
string $class,
ManagerRegistry $registry,
CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
// @phpstan-ignore-next-line
object $userPasswordHasher
private object $userPasswordHasher
) {
parent::__construct($class, $registry);

$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
$this->userPasswordHasher = $userPasswordHasher;
}

/**
8 changes: 1 addition & 7 deletions src/Form/Type/ResettingFormType.php
Original file line number Diff line number Diff line change
@@ -22,17 +22,11 @@

final class ResettingFormType extends AbstractType
{
/**
* @phpstan-var class-string<UserInterface>
*/
private string $class;

/**
* @phpstan-param class-string<UserInterface> $class
*/
public function __construct(string $class)
public function __construct(private string $class)
{
$this->class = $class;
}

public function buildForm(FormBuilderInterface $builder, array $options): void
49 changes: 20 additions & 29 deletions src/Form/Type/RolesMatrixType.php
Original file line number Diff line number Diff line change
@@ -25,11 +25,8 @@
*/
final class RolesMatrixType extends AbstractType
{
private ExpandableRolesBuilderInterface $rolesBuilder;

public function __construct(ExpandableRolesBuilderInterface $rolesBuilder)
public function __construct(private ExpandableRolesBuilderInterface $rolesBuilder)
{
$this->rolesBuilder = $rolesBuilder;
}

public function configureOptions(OptionsResolver $resolver): void
@@ -47,34 +44,28 @@ public function configureOptions(OptionsResolver $resolver): void

return array_combine($roles, $roles);
},
'choice_translation_domain' =>
/**
* @param bool|string|null $value
*
* @return bool|string|null
*/
static function (Options $options, $value) {
// if choice_translation_domain is true, then it's the same as translation_domain
if (true === $value) {
$value = $options['translation_domain'];
}
'choice_translation_domain' => static function (Options $options, bool|string|null $value): bool|string|null {
// if choice_translation_domain is true, then it's the same as translation_domain
if (true === $value) {
$value = $options['translation_domain'];
}

if (null === $value) {
// no translation domain yet, try to ask sonata admin
$admin = null;
if (isset($options['sonata_admin'])) {
$admin = $options['sonata_admin'];
}
if (null === $admin && isset($options['sonata_field_description'])) {
$admin = $options['sonata_field_description']->getAdmin();
}
if (null !== $admin) {
$value = $admin->getTranslationDomain();
}
if (null === $value) {
// no translation domain yet, try to ask sonata admin
$admin = null;
if (isset($options['sonata_admin'])) {
$admin = $options['sonata_admin'];
}
if (null === $admin && isset($options['sonata_field_description'])) {
$admin = $options['sonata_field_description']->getAdmin();
}
if (null !== $admin) {
$value = $admin->getTranslationDomain();
}
}

return $value;
},
return $value;
},
'excluded_roles' => [UserInterface::ROLE_DEFAULT],
'data_class' => null,
]);
5 changes: 1 addition & 4 deletions src/Listener/LastLoginListener.php
Original file line number Diff line number Diff line change
@@ -24,11 +24,8 @@
*/
final class LastLoginListener implements EventSubscriberInterface
{
private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
$this->userManager = $userManager;
}

public static function getSubscribedEvents(): array
12 changes: 3 additions & 9 deletions src/Listener/UserListener.php
Original file line number Diff line number Diff line change
@@ -30,16 +30,10 @@
*/
final class UserListener implements EventSubscriber
{
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater;

private UserManagerInterface $userManager;

public function __construct(
CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
UserManagerInterface $userManager
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater,
private UserManagerInterface $userManager
) {
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
$this->userManager = $userManager;
}

public function getSubscribedEvents(): array
@@ -87,7 +81,7 @@ private function updateUser(UserInterface $user): void

private function recomputeChangeSet(ObjectManager $om, UserInterface $user): void
{
$meta = $om->getClassMetadata(\get_class($user));
$meta = $om->getClassMetadata($user::class);

if ($om instanceof EntityManager) {
\assert($meta instanceof ORMClassMetadata);
28 changes: 5 additions & 23 deletions src/Mailer/Mailer.php
Original file line number Diff line number Diff line change
@@ -21,34 +21,16 @@

final class Mailer implements MailerInterface
{
private UrlGeneratorInterface $urlGenerator;

private Environment $twig;

private SymfonyMailerInterface $mailer;

/**
* @var array<string, string>
*/
private array $fromEmail;

private string $emailTemplate;

/**
* @param array<string, string> $fromEmail
*/
public function __construct(
UrlGeneratorInterface $urlGenerator,
Environment $twig,
SymfonyMailerInterface $mailer,
array $fromEmail,
string $emailTemplate
private UrlGeneratorInterface $urlGenerator,
private Environment $twig,
private SymfonyMailerInterface $mailer,
private array $fromEmail,
private string $emailTemplate
) {
$this->urlGenerator = $urlGenerator;
$this->twig = $twig;
$this->mailer = $mailer;
$this->fromEmail = $fromEmail;
$this->emailTemplate = $emailTemplate;
}

public function sendResettingEmailMessage(UserInterface $user): void
2 changes: 1 addition & 1 deletion src/Model/User.php
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

use Symfony\Component\Security\Core\User\UserInterface as SymfonyUserInterface;

abstract class User implements UserInterface
abstract class User implements UserInterface, \Stringable
{
/**
* @var int|string|null
2 changes: 1 addition & 1 deletion src/Security/Authorization/Voter/UserAclVoter.php
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ public function supportsAttribute($attribute): bool
*/
public function vote(TokenInterface $token, $subject, array $attributes): int
{
if (!\is_object($subject) || !$this->supportsClass(\get_class($subject))) {
if (!\is_object($subject) || !$this->supportsClass($subject::class)) {
return self::ACCESS_ABSTAIN;
}

20 changes: 4 additions & 16 deletions src/Security/RolesBuilder/AdminRolesBuilder.php
Original file line number Diff line number Diff line change
@@ -26,29 +26,17 @@
*/
final class AdminRolesBuilder implements AdminRolesBuilderInterface
{
private AuthorizationCheckerInterface $authorizationChecker;

private Pool $pool;

private SonataConfiguration $configuration;

private TranslatorInterface $translator;

/**
* @var string[]
*/
private array $excludeAdmins = [];

public function __construct(
AuthorizationCheckerInterface $authorizationChecker,
Pool $pool,
SonataConfiguration $configuration,
TranslatorInterface $translator
private AuthorizationCheckerInterface $authorizationChecker,
private Pool $pool,
private SonataConfiguration $configuration,
private TranslatorInterface $translator
) {
$this->authorizationChecker = $authorizationChecker;
$this->pool = $pool;
$this->configuration = $configuration;
$this->translator = $translator;
}

public function getPermissionLabels(): array
15 changes: 3 additions & 12 deletions src/Security/RolesBuilder/MatrixRolesBuilder.php
Original file line number Diff line number Diff line change
@@ -20,20 +20,11 @@
*/
final class MatrixRolesBuilder implements MatrixRolesBuilderInterface
{
private TokenStorageInterface $tokenStorage;

private AdminRolesBuilderInterface $adminRolesBuilder;

private ExpandableRolesBuilderInterface $securityRolesBuilder;

public function __construct(
TokenStorageInterface $tokenStorage,
AdminRolesBuilderInterface $adminRolesBuilder,
ExpandableRolesBuilderInterface $securityRolesBuilder
private TokenStorageInterface $tokenStorage,
private AdminRolesBuilderInterface $adminRolesBuilder,
private ExpandableRolesBuilderInterface $securityRolesBuilder
) {
$this->tokenStorage = $tokenStorage;
$this->adminRolesBuilder = $adminRolesBuilder;
$this->securityRolesBuilder = $securityRolesBuilder;
}

public function getRoles(?string $domain = null): array
23 changes: 4 additions & 19 deletions src/Security/RolesBuilder/SecurityRolesBuilder.php
Original file line number Diff line number Diff line change
@@ -24,30 +24,15 @@
*/
final class SecurityRolesBuilder implements ExpandableRolesBuilderInterface
{
private AuthorizationCheckerInterface $authorizationChecker;

private SonataConfiguration $configuration;

private TranslatorInterface $translator;

/**
* @var array<string, array<string>>
*/
private array $rolesHierarchy;

/**
* @param array<string, array<string>> $rolesHierarchy
*/
public function __construct(
AuthorizationCheckerInterface $authorizationChecker,
SonataConfiguration $configuration,
TranslatorInterface $translator,
array $rolesHierarchy = []
private AuthorizationCheckerInterface $authorizationChecker,
private SonataConfiguration $configuration,
private TranslatorInterface $translator,
private array $rolesHierarchy = []
) {
$this->authorizationChecker = $authorizationChecker;
$this->configuration = $configuration;
$this->translator = $translator;
$this->rolesHierarchy = $rolesHierarchy;
}

public function getExpandedRoles(?string $domain = null): array
11 changes: 4 additions & 7 deletions src/Security/UserProvider.php
Original file line number Diff line number Diff line change
@@ -24,11 +24,8 @@

final class UserProvider implements UserProviderInterface
{
private UserManagerInterface $userManager;

public function __construct(UserManagerInterface $userManager)
public function __construct(private UserManagerInterface $userManager)
{
$this->userManager = $userManager;
}

/**
@@ -53,11 +50,11 @@ public function loadUserByIdentifier(string $identifier): SecurityUserInterface
public function refreshUser(SecurityUserInterface $user): SecurityUserInterface
{
if (!$user instanceof UserInterface) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', UserInterface::class, \get_class($user)));
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', UserInterface::class, $user::class));
}

if (!$this->supportsClass(\get_class($user))) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), \get_class($user)));
if (!$this->supportsClass($user::class)) {
throw new UnsupportedUserException(sprintf('Expected an instance of %s, but got "%s".', $this->userManager->getClass(), $user::class));
}

if (null === $reloadedUser = $this->userManager->findOneBy(['id' => $user->getId()])) {
28 changes: 5 additions & 23 deletions src/Twig/GlobalVariables.php
Original file line number Diff line number Diff line change
@@ -21,34 +21,16 @@
*/
final class GlobalVariables
{
private ?Pool $pool;

private string $defaultAvatar;

private bool $impersonatingEnabled;

private string $impersonatingRoute;

/**
* @var array<string, mixed>
*/
private array $impersonatingRouteParameters;

/**
* @param array<string, mixed> $impersonatingRouteParameters
*/
public function __construct(
?Pool $pool,
string $defaultAvatar,
bool $impersonatingEnabled,
string $impersonatingRoute,
array $impersonatingRouteParameters = []
private ?Pool $pool,
private string $defaultAvatar,
private bool $impersonatingEnabled,
private string $impersonatingRoute,
private array $impersonatingRouteParameters = []
) {
$this->pool = $pool;
$this->defaultAvatar = $defaultAvatar;
$this->impersonatingEnabled = $impersonatingEnabled;
$this->impersonatingRoute = $impersonatingRoute;
$this->impersonatingRouteParameters = $impersonatingRouteParameters;
}

/**
5 changes: 1 addition & 4 deletions src/Twig/RolesMatrixExtension.php
Original file line number Diff line number Diff line change
@@ -26,11 +26,8 @@
*/
final class RolesMatrixExtension extends AbstractExtension
{
private MatrixRolesBuilderInterface $rolesBuilder;

public function __construct(MatrixRolesBuilderInterface $rolesBuilder)
public function __construct(private MatrixRolesBuilderInterface $rolesBuilder)
{
$this->rolesBuilder = $rolesBuilder;
}

public function getFunctions(): array
5 changes: 1 addition & 4 deletions src/Validator/UserInitializer.php
Original file line number Diff line number Diff line change
@@ -22,11 +22,8 @@
*/
final class UserInitializer implements ObjectInitializerInterface
{
private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater;

public function __construct(CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater)
public function __construct(private CanonicalFieldsUpdaterInterface $canonicalFieldsUpdater)
{
$this->canonicalFieldsUpdater = $canonicalFieldsUpdater;
}

/**
6 changes: 3 additions & 3 deletions tests/Security/UserProviderTest.php
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ public function testRefreshUserBy(): void
->willReturn($refreshedUser);
$this->userManager->expects(static::atLeastOnce())
->method('getClass')
->willReturn(\get_class($user));
->willReturn($user::class);

static::assertSame($refreshedUser, $this->userProvider->refreshUser($user));
}
@@ -98,7 +98,7 @@ public function testRefreshDeleted(): void
$this->userManager->expects(static::once())->method('findOneBy');
$this->userManager->expects(static::atLeastOnce())
->method('getClass')
->willReturn(\get_class($user));
->willReturn($user::class);

// @phpstan-ignore-next-line
$this->expectException(class_exists(UserNotFoundException::class) ? UserNotFoundException::class : UsernameNotFoundException::class);
@@ -122,7 +122,7 @@ public function testRefreshInvalidUserClass(): void

$this->userManager->expects(static::atLeastOnce())
->method('getClass')
->willReturn(\get_class($user));
->willReturn($user::class);

$this->expectException(UnsupportedUserException::class);