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

Mark all fields as readonly #707

Merged
merged 2 commits into from
Jul 31, 2023
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
2 changes: 1 addition & 1 deletion docs/controller_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resetting to go to the homepage.
*/
class PasswordResettingListener implements EventSubscriberInterface
{
private $router;
private readonly $router;

public function __construct(UrlGeneratorInterface $router)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Action/AccountDeletionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@

final class AccountDeletionAction
{
private Environment $twig;
private readonly Environment $twig;

private RouterInterface $router;
private readonly RouterInterface $router;

private UserManager $userManager;
private readonly UserManager $userManager;

private TokenStorageInterface $tokenStorage;
private readonly TokenStorageInterface $tokenStorage;

private FormFactoryInterface $formFactory;
private readonly FormFactoryInterface $formFactory;

private EventDispatcherInterface $eventDispatcher;
private readonly EventDispatcherInterface $eventDispatcher;

public function __construct(
Environment $twig,
Expand Down
6 changes: 3 additions & 3 deletions src/Action/CheckEmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

final class CheckEmailAction
{
private Environment $twig;
private readonly Environment $twig;

private RouterInterface $router;
private readonly RouterInterface $router;

private int $retryTtl;
private readonly int $retryTtl;

public function __construct(Environment $twig, RouterInterface $router, int $retryTtl)
{
Expand Down
12 changes: 6 additions & 6 deletions src/Action/LoginAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@

final class LoginAction
{
private Environment $twig;
private readonly Environment $twig;

private EventDispatcherInterface $eventDispatcher;
private readonly EventDispatcherInterface $eventDispatcher;

private FormFactoryInterface $formFactory;
private readonly FormFactoryInterface $formFactory;

private RouterInterface $router;
private readonly RouterInterface $router;

private CsrfTokenManagerInterface $csrfTokenManager;
private readonly CsrfTokenManagerInterface $csrfTokenManager;

private AuthenticationUtils $authenticationUtils;
private readonly AuthenticationUtils $authenticationUtils;

public function __construct(
Environment $twig,
Expand All @@ -62,27 +62,27 @@
public function __invoke(Request $request): Response
{
$event = new GetResponseLoginEvent($request);
$this->eventDispatcher->dispatch($event, NucleosUserEvents::SECURITY_LOGIN_INITIALIZE);

Check warning on line 65 in src/Action/LoginAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ public function __invoke(Request $request) : Response { $event = new GetResponseLoginEvent($request); - $this->eventDispatcher->dispatch($event, NucleosUserEvents::SECURITY_LOGIN_INITIALIZE); + if (null !== $event->getResponse()) { return $event->getResponse(); }

if (null !== $event->getResponse()) {
return $event->getResponse();
}

$form = $this->formFactory
->create(LoginFormType::class, null, [

Check warning on line 72 in src/Action/LoginAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ if (null !== $event->getResponse()) { return $event->getResponse(); } - $form = $this->formFactory->create(LoginFormType::class, null, ['action' => $this->router->generate('nucleos_user_security_check'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'security.login.submit']); + $form = $this->formFactory->create(LoginFormType::class, null, ['method' => 'POST'])->add('save', SubmitType::class, ['label' => 'security.login.submit']); return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); } }
'action' => $this->router->generate('nucleos_user_security_check'),
'method' => 'POST',
])
->add('save', SubmitType::class, [

Check warning on line 76 in src/Action/LoginAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ if (null !== $event->getResponse()) { return $event->getResponse(); } - $form = $this->formFactory->create(LoginFormType::class, null, ['action' => $this->router->generate('nucleos_user_security_check'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'security.login.submit']); + $form = $this->formFactory->create(LoginFormType::class, null, ['action' => $this->router->generate('nucleos_user_security_check'), 'method' => 'POST'])->add('save', SubmitType::class, []); return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); } }
'label' => 'security.login.submit',
])
;

return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', [
'form' => $form->createView(),
'last_username' => $this->authenticationUtils->getLastUsername(),

Check warning on line 83 in src/Action/LoginAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItem": --- Original +++ New @@ @@ return $event->getResponse(); } $form = $this->formFactory->create(LoginFormType::class, null, ['action' => $this->router->generate('nucleos_user_security_check'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'security.login.submit']); - return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); + return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' > $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); } }
'error' => $this->authenticationUtils->getLastAuthenticationError(),

Check warning on line 84 in src/Action/LoginAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItem": --- Original +++ New @@ @@ return $event->getResponse(); } $form = $this->formFactory->create(LoginFormType::class, null, ['action' => $this->router->generate('nucleos_user_security_check'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'security.login.submit']); - return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); + return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' > $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); } }
'csrf_token' => $this->csrfTokenManager->getToken('authenticate'),

Check warning on line 85 in src/Action/LoginAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItem": --- Original +++ New @@ @@ return $event->getResponse(); } $form = $this->formFactory->create(LoginFormType::class, null, ['action' => $this->router->generate('nucleos_user_security_check'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'security.login.submit']); - return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' => $this->csrfTokenManager->getToken('authenticate')])); + return new Response($this->twig->render('@NucleosUser/Security/login.html.twig', ['form' => $form->createView(), 'last_username' => $this->authenticationUtils->getLastUsername(), 'error' => $this->authenticationUtils->getLastAuthenticationError(), 'csrf_token' > $this->csrfTokenManager->getToken('authenticate')])); } }
]));
}
}
6 changes: 3 additions & 3 deletions src/Action/RequestResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

final class RequestResetAction
{
private Environment $twig;
private readonly Environment $twig;

private FormFactoryInterface $formFactory;
private readonly FormFactoryInterface $formFactory;

private RouterInterface $router;
private readonly RouterInterface $router;

public function __construct(Environment $twig, FormFactoryInterface $formFactory, RouterInterface $router)
{
Expand All @@ -36,11 +36,11 @@
public function __invoke(): Response
{
$form = $this->formFactory
->create(RequestPasswordFormType::class, null, [

Check warning on line 39 in src/Action/RequestResetAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ } public function __invoke() : Response { - $form = $this->formFactory->create(RequestPasswordFormType::class, null, ['action' => $this->router->generate('nucleos_user_resetting_send_email'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'resetting.request.submit']); + $form = $this->formFactory->create(RequestPasswordFormType::class, null, ['method' => 'POST'])->add('save', SubmitType::class, ['label' => 'resetting.request.submit']); return new Response($this->twig->render('@NucleosUser/Resetting/request.html.twig', ['form' => $form->createView()])); } }
'action' => $this->router->generate('nucleos_user_resetting_send_email'),
'method' => 'POST',
])
->add('save', SubmitType::class, [

Check warning on line 43 in src/Action/RequestResetAction.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "ArrayItemRemoval": --- Original +++ New @@ @@ } public function __invoke() : Response { - $form = $this->formFactory->create(RequestPasswordFormType::class, null, ['action' => $this->router->generate('nucleos_user_resetting_send_email'), 'method' => 'POST'])->add('save', SubmitType::class, ['label' => 'resetting.request.submit']); + $form = $this->formFactory->create(RequestPasswordFormType::class, null, ['action' => $this->router->generate('nucleos_user_resetting_send_email'), 'method' => 'POST'])->add('save', SubmitType::class, []); return new Response($this->twig->render('@NucleosUser/Resetting/request.html.twig', ['form' => $form->createView()])); } }
'label' => 'resetting.request.submit',
])
;
Expand Down
12 changes: 6 additions & 6 deletions src/Action/ResetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@

final class ResetAction
{
private Environment $twig;
private readonly Environment $twig;

private RouterInterface $router;
private readonly RouterInterface $router;

private EventDispatcherInterface $eventDispatcher;
private readonly EventDispatcherInterface $eventDispatcher;

private FormFactoryInterface $formFactory;
private readonly FormFactoryInterface $formFactory;

private UserManager $userManager;
private readonly UserManager $userManager;

private string $loggedinRoute;
private readonly string $loggedinRoute;

public function __construct(
Environment $twig,
Expand Down
14 changes: 7 additions & 7 deletions src/Action/SendEmailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@

final class SendEmailAction
{
private RouterInterface $router;
private readonly RouterInterface $router;

private EventDispatcherInterface $eventDispatcher;
private readonly EventDispatcherInterface $eventDispatcher;

private UserManager $userManager;
private readonly UserManager $userManager;

private TokenGenerator $tokenGenerator;
private readonly TokenGenerator $tokenGenerator;

private ResettingMailer $mailer;
private readonly ResettingMailer $mailer;

private int $retryTtl;
private readonly int $retryTtl;

private UserProviderInterface $userProvider;
private readonly UserProviderInterface $userProvider;

public function __construct(
RouterInterface $router,
Expand Down
14 changes: 7 additions & 7 deletions src/Action/UpdateSecurityAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@

final class UpdateSecurityAction
{
private Environment $twig;
private readonly Environment $twig;

private RouterInterface $router;
private readonly RouterInterface $router;

private Security $security;
private readonly Security $security;

private EventDispatcherInterface $eventDispatcher;
private readonly EventDispatcherInterface $eventDispatcher;

private FormFactoryInterface $formFactory;
private readonly FormFactoryInterface $formFactory;

private UserManipulator $userManipulator;
private readonly UserManipulator $userManipulator;

private UserManager $userManager;
private readonly UserManager $userManager;

public function __construct(
Environment $twig,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ActivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{
protected static $defaultName = 'nucleos:user:activate';

private UserManipulator $userManipulator;
private readonly UserManipulator $userManipulator;

public function __construct(UserManipulator $userManipulator)
{
Expand Down Expand Up @@ -67,7 +67,7 @@
{
if (!$input->getArgument('username')) {
$question = new Question('Please choose a username:');
$question->setValidator(static function ($username) {

Check warning on line 70 in src/Command/ActivateUserCommand.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ { if (!$input->getArgument('username')) { $question = new Question('Please choose a username:'); - $question->setValidator(static function ($username) { - if ('' === trim($username)) { - throw new RuntimeException('Username can not be empty'); - } - return $username; - }); + $answer = $this->getHelper('question')->ask($input, $output, $question); $input->setArgument('username', $answer); } } }
if ('' === trim($username)) {
throw new RuntimeException('Username can not be empty');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ChangePasswordCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{
protected static $defaultName = 'nucleos:user:change-password';

private UserManipulator $userManipulator;
private readonly UserManipulator $userManipulator;

public function __construct(UserManipulator $userManipulator)
{
Expand Down Expand Up @@ -78,7 +78,7 @@

if (!$input->getArgument('username')) {
$question = new Question('Please give the username:');
$question->setValidator(static function ($username) {

Check warning on line 81 in src/Command/ChangePasswordCommand.php

View workflow job for this annotation

GitHub Actions / run / Mutation Tests (8.2)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ $questions = []; if (!$input->getArgument('username')) { $question = new Question('Please give the username:'); - $question->setValidator(static function ($username) { - if ('' === trim($username)) { - throw new RuntimeException('Username can not be empty'); - } - return $username; - }); + $questions['username'] = $question; } if (!$input->getArgument('password')) {
if ('' === trim($username)) {
throw new RuntimeException('Username can not be empty');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CreateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class CreateUserCommand extends Command
{
protected static $defaultName = 'nucleos:user:create';

private UserManipulator $userManipulator;
private readonly UserManipulator $userManipulator;

public function __construct(UserManipulator $userManipulator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/DeactivateUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class DeactivateUserCommand extends Command
{
protected static $defaultName = 'nucleos:user:deactivate';

private UserManipulator $userManipulator;
private readonly UserManipulator $userManipulator;

public function __construct(UserManipulator $userManipulator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/RoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

abstract class RoleCommand extends Command
{
private UserManipulator $userManipulator;
private readonly UserManipulator $userManipulator;

public function __construct(UserManipulator $userManipulator)
{
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/NucleosUserExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class NucleosUserExtension extends Extension implements PrependExtensionIn
* @var array<string, array<string, string>>
*/
private static array $doctrineDrivers = [
'orm' => [
'orm' => [
'registry' => 'doctrine',
'tag' => 'doctrine.event_subscriber',
],
Expand Down Expand Up @@ -212,7 +212,7 @@ private function loadResetting(array $config, ContainerBuilder $container, FileL
$container->setParameter('nucleos_user.resetting.from_email', $fromEmail);

$this->remapParametersNamespaces($config, $container, [
'' => [
'' => [
'retry_ttl' => 'nucleos_user.resetting.retry_ttl',
'token_ttl' => 'nucleos_user.resetting.token_ttl',
],
Expand Down
6 changes: 3 additions & 3 deletions src/Doctrine/GroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
*/
final class GroupManager extends BaseGroupManager
{
private ObjectManager $objectManager;
private readonly ObjectManager $objectManager;

/**
* @phpstan-var class-string<GroupTemplate>
*/
private string $class;
private readonly string $class;

/**
* @phpstan-var ObjectRepository<GroupTemplate>
*/
private ObjectRepository $repository;
private readonly ObjectRepository $repository;

/**
* @phpstan-param class-string<GroupTemplate> $class
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/UserListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

final class UserListener implements EventSubscriber
{
private UserPasswordHasherInterface $userPasswordHasher;
private readonly UserPasswordHasherInterface $userPasswordHasher;

public function __construct(UserPasswordHasherInterface $userPasswordHasher)
{
Expand Down
9 changes: 2 additions & 7 deletions src/Doctrine/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

final class UserManager extends BaseUserManager
{
private ObjectManager $objectManager;
private readonly ObjectManager $objectManager;

/**
* @phpstan-var class-string<UserInterface>
*/
private string $class;
private readonly string $class;

/**
* @phpstan-param class-string<UserInterface> $class
Expand All @@ -44,11 +44,6 @@ public function deleteUser(UserInterface $user): void

public function getClass(): string
{
if (false !== strpos($this->class, ':')) {
$metadata = $this->objectManager->getClassMetadata($this->class);
$this->class = $metadata->getName();
}

return $this->class;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Event/AccountDeletionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

class AccountDeletionEvent extends Event
{
private Request $request;
private readonly Request $request;

private UserInterface $user;
private readonly UserInterface $user;

public function __construct(UserInterface $user, Request $request)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AccountDeletionResponseEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

final class AccountDeletionResponseEvent extends AccountDeletionEvent
{
private Response $response;
private readonly Response $response;

public function __construct(UserInterface $user, Request $request, Response $response)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Event/FormEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

class FormEvent extends Event
{
private FormInterface $form;
private readonly FormInterface $form;

private Request $request;
private readonly Request $request;

private ?Response $response = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Event/GetResponseLoginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class GetResponseLoginEvent extends Event
{
private ?Request $request;
private readonly ?Request $request;

private ?Response $response = null;

Expand Down
4 changes: 2 additions & 2 deletions src/Event/GroupEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

class GroupEvent extends Event
{
private GroupInterface $group;
private readonly GroupInterface $group;

private Request $request;
private readonly Request $request;

public function __construct(GroupInterface $group, Request $request)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Event/UserEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UserEvent extends Event
{
protected ?Request $request = null;

protected UserInterface $user;
protected readonly UserInterface $user;

public function __construct(UserInterface $user, Request $request = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/AuthenticationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

final class AuthenticationListener implements EventSubscriberInterface
{
private LoginManager $loginManager;
private readonly LoginManager $loginManager;

private string $firewallName;
private readonly string $firewallName;

public function __construct(LoginManager $loginManager, string $firewallName)
{
Expand Down
4 changes: 2 additions & 2 deletions src/EventListener/FlashListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ final class FlashListener implements EventSubscriberInterface
NucleosUserEvents::ACCOUNT_DELETION_SUCCESS => 'deletion.success',
];

private RequestStack $requestStack;
private readonly RequestStack $requestStack;

private TranslatorInterface $translator;
private readonly TranslatorInterface $translator;

public function __construct(RequestStack $requestStack, TranslatorInterface $translator)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/LastLoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

final class LastLoginListener implements EventSubscriberInterface
{
private UserManager $userManager;
private readonly UserManager $userManager;

public function __construct(UserManager $userManager)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EventListener/LocaleEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

final class LocaleEventListener implements EventSubscriberInterface
{
private LocaleAwareTranslator $translator;
private readonly LocaleAwareTranslator $translator;

public function __construct(LocaleAwareTranslator $translator)
{
Expand Down
Loading