Skip to content

chore: readonly properties #1406

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

Merged
merged 1 commit into from
Mar 13, 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
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/Command/AddUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class AddUserCommand extends Command
private SymfonyStyle $io;

public function __construct(
private EntityManagerInterface $entityManager,
private UserPasswordHasherInterface $passwordHasher,
private Validator $validator,
private UserRepository $users
private readonly EntityManagerInterface $entityManager,
private readonly UserPasswordHasherInterface $passwordHasher,
private readonly Validator $validator,
private readonly UserRepository $users
) {
parent::__construct();
}
Expand Down Expand Up @@ -124,7 +124,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
if (null !== $username) {
$this->io->text(' > <info>Username</info>: '.$username);
} else {
$username = $this->io->ask('Username', null, [$this->validator, 'validateUsername']);
$username = $this->io->ask('Username', null, $this->validator->validateUsername(...));
$input->setArgument('username', $username);
}

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

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

Expand All @@ -153,7 +153,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
if (null !== $fullName) {
$this->io->text(' > <info>Full Name</info>: '.$fullName);
} else {
$fullName = $this->io->ask('Full Name', null, [$this->validator, 'validateFullName']);
$fullName = $this->io->ask('Full Name', null, $this->validator->validateFullName(...));
$input->setArgument('full-name', $fullName);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Command/DeleteUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class DeleteUserCommand extends Command
private SymfonyStyle $io;

public function __construct(
private EntityManagerInterface $entityManager,
private Validator $validator,
private UserRepository $users,
private LoggerInterface $logger
private readonly EntityManagerInterface $entityManager,
private readonly Validator $validator,
private readonly UserRepository $users,
private readonly LoggerInterface $logger
) {
parent::__construct();
}
Expand Down Expand Up @@ -101,7 +101,7 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
'',
]);

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

Expand Down
6 changes: 3 additions & 3 deletions src/Command/ListUsersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
class ListUsersCommand extends Command
{
public function __construct(
private MailerInterface $mailer,
private string $emailSender,
private UserRepository $users
private readonly MailerInterface $mailer,
private readonly string $emailSender,
private readonly UserRepository $users
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
class AppFixtures extends Fixture
{
public function __construct(
private UserPasswordHasherInterface $passwordHasher,
private SluggerInterface $slugger
private readonly UserPasswordHasherInterface $passwordHasher,
private readonly SluggerInterface $slugger
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventSubscriber/CheckRequirementsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class CheckRequirementsSubscriber implements EventSubscriberInterface
{
public function __construct(
private EntityManagerInterface $entityManager
private readonly EntityManagerInterface $entityManager
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/EventSubscriber/CommentNotificationSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
class CommentNotificationSubscriber implements EventSubscriberInterface
{
public function __construct(
private MailerInterface $mailer,
private UrlGeneratorInterface $urlGenerator,
private TranslatorInterface $translator,
private string $sender
private readonly MailerInterface $mailer,
private readonly UrlGeneratorInterface $urlGenerator,
private readonly TranslatorInterface $translator,
private readonly string $sender
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/EventSubscriber/ControllerSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
class ControllerSubscriber implements EventSubscriberInterface
{
public function __construct(
private SourceCodeExtension $twigExtension
private readonly SourceCodeExtension $twigExtension
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class RedirectToPreferredLocaleSubscriber implements EventSubscriberInterface
* @var string[]
*/
private array $locales;
private string $defaultLocale;
private readonly string $defaultLocale;

public function __construct(
private UrlGeneratorInterface $urlGenerator,
private readonly UrlGeneratorInterface $urlGenerator,
string $locales,
?string $defaultLocale = null
) {
Expand Down
2 changes: 1 addition & 1 deletion src/Form/DataTransformer/TagArrayToStringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class TagArrayToStringTransformer implements DataTransformerInterface
{
public function __construct(
private TagRepository $tags
private readonly TagRepository $tags
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/PostType.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PostType extends AbstractType
{
// Form types are services, so you can inject other services in them if needed
public function __construct(
private SluggerInterface $slugger
private readonly SluggerInterface $slugger
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/DateTimePickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class DateTimePickerType extends AbstractType
{
public function __construct(
private MomentFormatConverter $formatConverter
private readonly MomentFormatConverter $formatConverter
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/TagsInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class TagsInputType extends AbstractType
{
public function __construct(
private TagRepository $tags
private readonly TagRepository $tags
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Paginator
*
* See https://symfony.com/doc/current/best_practices.html#use-constants-to-define-options-that-rarely-change
*/
public const PAGE_SIZE = 10;
final public const PAGE_SIZE = 10;

private int $currentPage;
private int $numResults;
Expand All @@ -37,8 +37,8 @@ class Paginator
private \Traversable $results;

public function __construct(
private DoctrineQueryBuilder $queryBuilder,
private int $pageSize = self::PAGE_SIZE
private readonly DoctrineQueryBuilder $queryBuilder,
private readonly int $pageSize = self::PAGE_SIZE
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Twig/AppExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppExtension extends AbstractExtension
/**
* @var string[]
*/
private array $localeCodes;
private readonly array $localeCodes;

/**
* @var list<array{code: string, name: string}>|null
Expand All @@ -46,7 +46,7 @@ public function __construct(string $locales)
public function getFunctions(): array
{
return [
new TwigFunction('locales', [$this, 'getLocales']),
new TwigFunction('locales', $this->getLocales(...)),
];
}

Expand Down