Skip to content

Commit 682ebb6

Browse files
authored
Merge pull request #3074 from stof/improve_types
Improve type declarations in the project
2 parents bbdacd5 + f876bff commit 682ebb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+247
-72
lines changed

src/Command/ActivateUserCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use FOS\UserBundle\Util\UserManipulator;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Output\OutputInterface;
@@ -80,7 +81,10 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
8081

8182
return $username;
8283
});
83-
$answer = $this->getHelper('question')->ask($input, $output, $question);
84+
85+
$helper = $this->getHelper('question');
86+
\assert($helper instanceof QuestionHelper);
87+
$answer = $helper->ask($input, $output, $question);
8488

8589
$input->setArgument('username', $answer);
8690
}

src/Command/ChangePasswordCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use FOS\UserBundle\Util\UserManipulator;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Output\OutputInterface;
@@ -105,8 +106,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
105106
$questions['password'] = $question;
106107
}
107108

109+
$helper = $this->getHelper('question');
110+
\assert($helper instanceof QuestionHelper);
111+
108112
foreach ($questions as $name => $question) {
109-
$answer = $this->getHelper('question')->ask($input, $output, $question);
113+
$answer = $helper->ask($input, $output, $question);
110114
$input->setArgument($name, $answer);
111115
}
112116
}

src/Command/CreateUserCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use FOS\UserBundle\Util\UserManipulator;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Input\InputOption;
@@ -136,8 +137,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
136137
$questions['password'] = $question;
137138
}
138139

140+
$helper = $this->getHelper('question');
141+
\assert($helper instanceof QuestionHelper);
142+
139143
foreach ($questions as $name => $question) {
140-
$answer = $this->getHelper('question')->ask($input, $output, $question);
144+
$answer = $helper->ask($input, $output, $question);
141145
$input->setArgument($name, $answer);
142146
}
143147
}

src/Command/DeactivateUserCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use FOS\UserBundle\Util\UserManipulator;
1515
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Command\Command;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Output\OutputInterface;
@@ -80,7 +81,10 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
8081

8182
return $username;
8283
});
83-
$answer = $this->getHelper('question')->ask($input, $output, $question);
84+
85+
$helper = $this->getHelper('question');
86+
\assert($helper instanceof QuestionHelper);
87+
$answer = $helper->ask($input, $output, $question);
8488

8589
$input->setArgument('username', $answer);
8690
}

src/Command/RoleCommand.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use FOS\UserBundle\Util\UserManipulator;
1515
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Helper\QuestionHelper;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -102,8 +103,11 @@ protected function interact(InputInterface $input, OutputInterface $output): voi
102103
$questions['role'] = $question;
103104
}
104105

106+
$helper = $this->getHelper('question');
107+
\assert($helper instanceof QuestionHelper);
108+
105109
foreach ($questions as $name => $question) {
106-
$answer = $this->getHelper('question')->ask($input, $output, $question);
110+
$answer = $helper->ask($input, $output, $question);
107111
$input->setArgument($name, $answer);
108112
}
109113
}

src/Controller/RegistrationController.php

+4
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ private function getTargetUrlFromSession(SessionInterface $session): ?string
174174
{
175175
$token = $this->tokenStorage->getToken();
176176

177+
if (null === $token) {
178+
return null;
179+
}
180+
177181
if (method_exists($token, 'getFirewallName')) {
178182
$firewallName = $token->getFirewallName();
179183
} elseif (method_exists($token, 'getProviderKey')) {

src/Controller/SecurityController.php

+8
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@ public function loginAction(): Response
5151
]);
5252
}
5353

54+
/**
55+
* @return never
56+
*/
5457
public function checkAction()
5558
{
5659
throw new \RuntimeException('You must configure the check path to be handled by the firewall using form_login in your security firewall configuration.');
5760
}
5861

62+
/**
63+
* @return never
64+
*/
5965
public function logoutAction()
6066
{
6167
throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
@@ -64,6 +70,8 @@ public function logoutAction()
6470
/**
6571
* Renders the login template with the given parameters. Overwrite this function in
6672
* an extended controller to provide additional data for the login template.
73+
*
74+
* @param array<string, mixed> $data
6775
*/
6876
protected function renderLogin(array $data): Response
6977
{

src/DependencyInjection/Compiler/InjectRememberMeServicesPass.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class InjectRememberMeServicesPass implements CompilerPassInterface
2929
public function process(ContainerBuilder $container): void
3030
{
3131
$firewallName = $container->getParameter('fos_user.firewall_name');
32+
\assert(\is_string($firewallName));
3233
$loginManager = $container->getDefinition('fos_user.security.login_manager');
3334

3435
if ($container->has('security.authenticator.remember_me_handler.'.$firewallName)) {

src/DependencyInjection/Compiler/InjectUserCheckerPass.php

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class InjectUserCheckerPass implements CompilerPassInterface
2929
public function process(ContainerBuilder $container): void
3030
{
3131
$firewallName = $container->getParameter('fos_user.firewall_name');
32+
\assert(\is_string($firewallName));
3233
$loginManager = $container->findDefinition('fos_user.security.login_manager');
3334

3435
if ($container->has('security.user_checker.'.$firewallName)) {

src/DependencyInjection/Compiler/ValidationPass.php

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function process(ContainerBuilder $container): void
3232
}
3333

3434
$storage = $container->getParameter('fos_user.storage');
35+
\assert(\is_string($storage));
3536

3637
if ('custom' === $storage) {
3738
return;

src/DependencyInjection/FOSUserExtension.php

+26-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class FOSUserExtension extends Extension
2929
{
3030
/**
31-
* @var array
31+
* @var array<string, array{registry: string, tag: string, listener_class?: string}>
3232
*/
3333
private static $doctrineDrivers = [
3434
'orm' => [
@@ -46,8 +46,8 @@ class FOSUserExtension extends Extension
4646
],
4747
];
4848

49-
private $mailerNeeded = false;
50-
private $sessionNeeded = false;
49+
private bool $mailerNeeded = false;
50+
private bool $sessionNeeded = false;
5151

5252
public function load(array $configs, ContainerBuilder $container): void
5353
{
@@ -152,6 +152,11 @@ public function getNamespace(): string
152152
return 'http://friendsofsymfony.github.io/schema/dic/user';
153153
}
154154

155+
/**
156+
* /**
157+
* @param array<string, mixed> $config
158+
* @param array<string, string> $map
159+
*/
155160
protected function remapParameters(array $config, ContainerBuilder $container, array $map): void
156161
{
157162
foreach ($map as $name => $paramName) {
@@ -161,6 +166,10 @@ protected function remapParameters(array $config, ContainerBuilder $container, a
161166
}
162167
}
163168

169+
/**
170+
* @param array<string, mixed> $config
171+
* @param array<string, string|array<string, string>> $namespaces
172+
*/
164173
protected function remapParametersNamespaces(array $config, ContainerBuilder $container, array $namespaces): void
165174
{
166175
foreach ($namespaces as $ns => $map) {
@@ -182,6 +191,9 @@ protected function remapParametersNamespaces(array $config, ContainerBuilder $co
182191
}
183192
}
184193

194+
/**
195+
* @param array<string, mixed> $config
196+
*/
185197
private function loadProfile(array $config, ContainerBuilder $container, XmlFileLoader $loader): void
186198
{
187199
$loader->load('profile.xml');
@@ -191,6 +203,10 @@ private function loadProfile(array $config, ContainerBuilder $container, XmlFile
191203
]);
192204
}
193205

206+
/**
207+
* @param array<string, mixed> $config
208+
* @param array{address: string, sender_name: string} $fromEmail
209+
*/
194210
private function loadRegistration(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $fromEmail): void
195211
{
196212
$loader->load('registration.xml');
@@ -215,6 +231,9 @@ private function loadRegistration(array $config, ContainerBuilder $container, Xm
215231
]);
216232
}
217233

234+
/**
235+
* @param array<string, mixed> $config
236+
*/
218237
private function loadChangePassword(array $config, ContainerBuilder $container, XmlFileLoader $loader): void
219238
{
220239
$loader->load('change_password.xml');
@@ -224,6 +243,10 @@ private function loadChangePassword(array $config, ContainerBuilder $container,
224243
]);
225244
}
226245

246+
/**
247+
* @param array<string, mixed> $config
248+
* @param array{address: string, sender_name: string} $fromEmail
249+
*/
227250
private function loadResetting(array $config, ContainerBuilder $container, XmlFileLoader $loader, array $fromEmail): void
228251
{
229252
$this->mailerNeeded = true;

src/Doctrine/UserListener.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public function getSubscribedEvents(): array
5151

5252
/**
5353
* Pre persist listener based on doctrine common.
54+
*
55+
* @param LifecycleEventArgs<ObjectManager> $args
5456
*/
5557
public function prePersist(LifecycleEventArgs $args): void
5658
{
@@ -62,6 +64,8 @@ public function prePersist(LifecycleEventArgs $args): void
6264

6365
/**
6466
* Pre update listener based on doctrine common.
67+
*
68+
* @param LifecycleEventArgs<ObjectManager> $args
6569
*/
6670
public function preUpdate(LifecycleEventArgs $args): void
6771
{
@@ -86,15 +90,15 @@ private function updateUserFields(UserInterface $user): void
8690
*/
8791
private function recomputeChangeSet(ObjectManager $om, UserInterface $user): void
8892
{
89-
$meta = $om->getClassMetadata(get_class($user));
90-
9193
if ($om instanceof EntityManager) {
94+
$meta = $om->getClassMetadata(get_class($user));
9295
$om->getUnitOfWork()->recomputeSingleEntityChangeSet($meta, $user);
9396

9497
return;
9598
}
9699

97100
if ($om instanceof DocumentManager) {
101+
$meta = $om->getClassMetadata(get_class($user));
98102
$om->getUnitOfWork()->recomputeSingleDocumentChangeSet($meta, $user);
99103
}
100104
}

src/Doctrine/UserManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function findUserBy(array $criteria)
7676
}
7777

7878
/**
79-
* @return \Traversable<UserInterface>
79+
* @return iterable<UserInterface>
8080
*/
8181
public function findUsers()
8282
{

src/Event/FilterUserResponseEvent.php

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public function getResponse(): Response
3838

3939
/**
4040
* Sets a new response object.
41+
*
42+
* @return void
4143
*/
4244
public function setResponse(Response $response)
4345
{

src/Event/FormEvent.php

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ public function getRequest(): Request
5555
return $this->request;
5656
}
5757

58+
/**
59+
* @return void
60+
*/
5861
public function setResponse(Response $response)
5962
{
6063
$this->response = $response;

src/Event/GetResponseNullableUserEvent.php

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public function getRequest(): Request
5656
return $this->request;
5757
}
5858

59+
/**
60+
* @return void
61+
*/
5962
public function setResponse(Response $response)
6063
{
6164
$this->response = $response;

src/Event/GetResponseUserEvent.php

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class GetResponseUserEvent extends UserEvent
2323
*/
2424
private $response;
2525

26+
/**
27+
* @return void
28+
*/
2629
public function setResponse(Response $response)
2730
{
2831
$this->response = $response;

src/EventListener/AuthenticationListener.php

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public static function getSubscribedEvents(): array
5959

6060
/**
6161
* @param string $eventName
62+
*
63+
* @return void
6264
*/
6365
public function authenticate(FilterUserResponseEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
6466
{

src/EventListener/EmailConfirmationListener.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ public static function getSubscribedEvents(): array
4747
];
4848
}
4949

50+
/**
51+
* @return void
52+
*/
5053
public function onRegistrationSuccess(FormEvent $event)
5154
{
52-
/** @var $user \FOS\UserBundle\Model\UserInterface */
55+
/** @var \FOS\UserBundle\Model\UserInterface $user */
5356
$user = $event->getForm()->getData();
5457

5558
$user->setEnabled(false);

src/EventListener/FlashListener.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public static function getSubscribedEvents(): array
6666

6767
/**
6868
* @param string $eventName
69+
*
70+
* @return void
6971
*/
7072
public function addSuccessFlash(Event $event, $eventName)
7173
{
@@ -90,8 +92,8 @@ private function getSession(): Session
9092
/**
9193
* @param string $message
9294
*/
93-
private function trans($message, array $params = []): string
95+
private function trans($message): string
9496
{
95-
return $this->translator->trans($message, $params, 'FOSUserBundle');
97+
return $this->translator->trans($message, [], 'FOSUserBundle');
9698
}
9799
}

0 commit comments

Comments
 (0)