Skip to content

Commit ee044c7

Browse files
committed
feature #1406 chore: readonly properties (COil)
This PR was squashed before being merged into the main branch. Discussion ---------- chore: readonly properties + other PHP 8.1 upgrades (rector) Commits ------- 6a9fc06 chore: readonly properties
2 parents 12e361a + 6a9fc06 commit ee044c7

15 files changed

+47
-47
lines changed

composer.lock

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Command/AddUserCommand.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class AddUserCommand extends Command
5656
private SymfonyStyle $io;
5757

5858
public function __construct(
59-
private EntityManagerInterface $entityManager,
60-
private UserPasswordHasherInterface $passwordHasher,
61-
private Validator $validator,
62-
private UserRepository $users
59+
private readonly EntityManagerInterface $entityManager,
60+
private readonly UserPasswordHasherInterface $passwordHasher,
61+
private readonly Validator $validator,
62+
private readonly UserRepository $users
6363
) {
6464
parent::__construct();
6565
}
@@ -124,7 +124,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
124124
if (null !== $username) {
125125
$this->io->text(' > <info>Username</info>: '.$username);
126126
} else {
127-
$username = $this->io->ask('Username', null, [$this->validator, 'validateUsername']);
127+
$username = $this->io->ask('Username', null, $this->validator->validateUsername(...));
128128
$input->setArgument('username', $username);
129129
}
130130

@@ -135,7 +135,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
135135
if (null !== $password) {
136136
$this->io->text(' > <info>Password</info>: '.u('*')->repeat(u($password)->length()));
137137
} else {
138-
$password = $this->io->askHidden('Password (your type will be hidden)', [$this->validator, 'validatePassword']);
138+
$password = $this->io->askHidden('Password (your type will be hidden)', $this->validator->validatePassword(...));
139139
$input->setArgument('password', $password);
140140
}
141141

@@ -144,7 +144,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
144144
if (null !== $email) {
145145
$this->io->text(' > <info>Email</info>: '.$email);
146146
} else {
147-
$email = $this->io->ask('Email', null, [$this->validator, 'validateEmail']);
147+
$email = $this->io->ask('Email', null, $this->validator->validateEmail(...));
148148
$input->setArgument('email', $email);
149149
}
150150

@@ -153,7 +153,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
153153
if (null !== $fullName) {
154154
$this->io->text(' > <info>Full Name</info>: '.$fullName);
155155
} else {
156-
$fullName = $this->io->ask('Full Name', null, [$this->validator, 'validateFullName']);
156+
$fullName = $this->io->ask('Full Name', null, $this->validator->validateFullName(...));
157157
$input->setArgument('full-name', $fullName);
158158
}
159159
}

src/Command/DeleteUserCommand.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class DeleteUserCommand extends Command
4848
private SymfonyStyle $io;
4949

5050
public function __construct(
51-
private EntityManagerInterface $entityManager,
52-
private Validator $validator,
53-
private UserRepository $users,
54-
private LoggerInterface $logger
51+
private readonly EntityManagerInterface $entityManager,
52+
private readonly Validator $validator,
53+
private readonly UserRepository $users,
54+
private readonly LoggerInterface $logger
5555
) {
5656
parent::__construct();
5757
}
@@ -101,7 +101,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
101101
'',
102102
]);
103103

104-
$username = $this->io->ask('Username', null, [$this->validator, 'validateUsername']);
104+
$username = $this->io->ask('Username', null, $this->validator->validateUsername(...));
105105
$input->setArgument('username', $username);
106106
}
107107

src/Command/ListUsersCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
class ListUsersCommand extends Command
4747
{
4848
public function __construct(
49-
private MailerInterface $mailer,
50-
private string $emailSender,
51-
private UserRepository $users
49+
private readonly MailerInterface $mailer,
50+
private readonly string $emailSender,
51+
private readonly UserRepository $users
5252
) {
5353
parent::__construct();
5454
}

src/DataFixtures/AppFixtures.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
class AppFixtures extends Fixture
2626
{
2727
public function __construct(
28-
private UserPasswordHasherInterface $passwordHasher,
29-
private SluggerInterface $slugger
28+
private readonly UserPasswordHasherInterface $passwordHasher,
29+
private readonly SluggerInterface $slugger
3030
) {
3131
}
3232

src/EventSubscriber/CheckRequirementsSubscriber.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class CheckRequirementsSubscriber implements EventSubscriberInterface
3333
{
3434
public function __construct(
35-
private EntityManagerInterface $entityManager
35+
private readonly EntityManagerInterface $entityManager
3636
) {
3737
}
3838

src/EventSubscriber/CommentNotificationSubscriber.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
class CommentNotificationSubscriber implements EventSubscriberInterface
2929
{
3030
public function __construct(
31-
private MailerInterface $mailer,
32-
private UrlGeneratorInterface $urlGenerator,
33-
private TranslatorInterface $translator,
34-
private string $sender
31+
private readonly MailerInterface $mailer,
32+
private readonly UrlGeneratorInterface $urlGenerator,
33+
private readonly TranslatorInterface $translator,
34+
private readonly string $sender
3535
) {
3636
}
3737

src/EventSubscriber/ControllerSubscriber.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class ControllerSubscriber implements EventSubscriberInterface
2727
{
2828
public function __construct(
29-
private SourceCodeExtension $twigExtension
29+
private readonly SourceCodeExtension $twigExtension
3030
) {
3131
}
3232

src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class RedirectToPreferredLocaleSubscriber implements EventSubscriberInterface
3232
* @var string[]
3333
*/
3434
private array $locales;
35-
private string $defaultLocale;
35+
private readonly string $defaultLocale;
3636

3737
public function __construct(
38-
private UrlGeneratorInterface $urlGenerator,
38+
private readonly UrlGeneratorInterface $urlGenerator,
3939
string $locales,
4040
?string $defaultLocale = null
4141
) {

src/Form/DataTransformer/TagArrayToStringTransformer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class TagArrayToStringTransformer implements DataTransformerInterface
3131
{
3232
public function __construct(
33-
private TagRepository $tags
33+
private readonly TagRepository $tags
3434
) {
3535
}
3636

src/Form/PostType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PostType extends AbstractType
3333
{
3434
// Form types are services, so you can inject other services in them if needed
3535
public function __construct(
36-
private SluggerInterface $slugger
36+
private readonly SluggerInterface $slugger
3737
) {
3838
}
3939

src/Form/Type/DateTimePickerType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class DateTimePickerType extends AbstractType
3131
{
3232
public function __construct(
33-
private MomentFormatConverter $formatConverter
33+
private readonly MomentFormatConverter $formatConverter
3434
) {
3535
}
3636

src/Form/Type/TagsInputType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
class TagsInputType extends AbstractType
3232
{
3333
public function __construct(
34-
private TagRepository $tags
34+
private readonly TagRepository $tags
3535
) {
3636
}
3737

src/Pagination/Paginator.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Paginator
2626
*
2727
* See https://symfony.com/doc/current/best_practices.html#use-constants-to-define-options-that-rarely-change
2828
*/
29-
public const PAGE_SIZE = 10;
29+
final public const PAGE_SIZE = 10;
3030

3131
private int $currentPage;
3232
private int $numResults;
@@ -37,8 +37,8 @@ class Paginator
3737
private \Traversable $results;
3838

3939
public function __construct(
40-
private DoctrineQueryBuilder $queryBuilder,
41-
private int $pageSize = self::PAGE_SIZE
40+
private readonly DoctrineQueryBuilder $queryBuilder,
41+
private readonly int $pageSize = self::PAGE_SIZE
4242
) {
4343
}
4444

src/Twig/AppExtension.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class AppExtension extends AbstractExtension
2727
/**
2828
* @var string[]
2929
*/
30-
private array $localeCodes;
30+
private readonly array $localeCodes;
3131

3232
/**
3333
* @var list<array{code: string, name: string}>|null
@@ -46,7 +46,7 @@ public function __construct(string $locales)
4646
public function getFunctions(): array
4747
{
4848
return [
49-
new TwigFunction('locales', [$this, 'getLocales']),
49+
new TwigFunction('locales', $this->getLocales(...)),
5050
];
5151
}
5252

0 commit comments

Comments
 (0)