Skip to content

Commit 97745a5

Browse files
authored
IBX-9727: Added missing strict types and adapted the codebase to PHP 8.3 (#113)
1 parent 338d40e commit 97745a5

File tree

137 files changed

+677
-2199
lines changed

Some content is hidden

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

137 files changed

+677
-2199
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 540 deletions
Large diffs are not rendered by default.

src/bundle/Command/AuditUserDatabaseCommand.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,17 @@
1919

2020
final class AuditUserDatabaseCommand extends Command
2121
{
22-
private ContentTypeService $contentTypeService;
23-
24-
private UserService $userService;
25-
26-
private Connection $connection;
27-
2822
public function __construct(
29-
ContentTypeService $contentTypeService,
30-
UserService $userService,
31-
Connection $connection
23+
private readonly ContentTypeService $contentTypeService,
24+
private readonly UserService $userService,
25+
private readonly Connection $connection
3226
) {
3327
parent::__construct('ibexa:user:audit-database');
34-
35-
$this->contentTypeService = $contentTypeService;
36-
$this->userService = $userService;
37-
$this->connection = $connection;
3828
}
3929

4030
/**
4131
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
32+
* @throws \Doctrine\DBAL\Exception
4233
*/
4334
public function execute(
4435
InputInterface $input,
@@ -96,7 +87,7 @@ public function execute(
9687
foreach ($logins as $record) {
9788
$login = $record['login'];
9889

99-
if (!preg_match(sprintf('/%s/', $pattern), $login)) {
90+
if (!preg_match(sprintf('/%s/', $pattern), (string) $login)) {
10091
$output->writeln(sprintf(' - Login %s does not match', $login));
10192
}
10293
}
@@ -109,7 +100,7 @@ public function execute(
109100
}
110101

111102
/**
112-
* @return \Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition[]
103+
* @return list<\Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition>
113104
*/
114105
private function getUserFieldDefinitions(): array
115106
{
@@ -130,6 +121,9 @@ private function getUserFieldDefinitions(): array
130121
return $userFieldDefinitions;
131122
}
132123

124+
/**
125+
* @param list<\Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition> $userFieldDefinitions
126+
*/
133127
private function isUniqueEmailRequired(array $userFieldDefinitions): bool
134128
{
135129
foreach ($userFieldDefinitions as $userFieldDefinition) {

src/bundle/Command/UpdateUserCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111111
$userUpdateStruct->enabled = $this->resolveEnabledFlag($enable, $disable);
112112

113113
$this->repository->sudo(
114-
function () use ($user, $userUpdateStruct): User {
115-
return $this->userService->updateUser($user, $userUpdateStruct);
116-
}
114+
fn (): User => $this->userService->updateUser($user, $userUpdateStruct)
117115
);
118116

119117
$io->success(sprintf(

src/bundle/Controller/DefaultProfileImageController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414

1515
final class DefaultProfileImageController extends Controller
1616
{
17-
private ConfigResolverInterface $configResolver;
18-
1917
public function __construct(
20-
ConfigResolverInterface $configResolver
18+
private readonly ConfigResolverInterface $configResolver
2119
) {
22-
$this->configResolver = $configResolver;
2320
}
2421

2522
public function initialsAction(Request $request): Response
@@ -38,6 +35,9 @@ public function initialsAction(Request $request): Response
3835
], $response);
3936
}
4037

38+
/**
39+
* @return array{text: string, background: string}
40+
*/
4141
private function getInitialsColors(string $initials): array
4242
{
4343
$colors = $this->configResolver->getParameter('user.default_profile_image.colors');

src/bundle/Controller/PasswordChangeController.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,19 @@ final class PasswordChangeController extends Controller implements RestrictedCon
2626
{
2727
use AuthenticatedRememberedCheckTrait;
2828

29-
private ActionResultHandler $actionResultHandler;
30-
31-
private UserService $userService;
32-
33-
private FormFactory $formFactory;
34-
35-
private TokenStorageInterface $tokenStorage;
36-
37-
private array $siteAccessGroups;
38-
29+
/**
30+
* @param array<string, list<string>> $siteAccessGroups
31+
*/
3932
public function __construct(
40-
ActionResultHandler $actionResultHandler,
41-
UserService $userService,
42-
FormFactory $formFactory,
43-
TokenStorageInterface $tokenStorage,
44-
array $siteAccessGroups
33+
private ActionResultHandler $actionResultHandler,
34+
private UserService $userService,
35+
private FormFactory $formFactory,
36+
private TokenStorageInterface $tokenStorage,
37+
private array $siteAccessGroups
4538
) {
46-
$this->actionResultHandler = $actionResultHandler;
47-
$this->userService = $userService;
48-
$this->formFactory = $formFactory;
49-
$this->tokenStorage = $tokenStorage;
50-
$this->siteAccessGroups = $siteAccessGroups;
5139
}
5240

5341
/**
54-
* @param \Symfony\Component\HttpFoundation\Request $request
55-
*
56-
* @return \Ibexa\User\View\ChangePassword\FormView|\Ibexa\User\View\ChangePassword\SuccessView|\Symfony\Component\HttpFoundation\RedirectResponse
57-
*
5842
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
5943
*/
6044
public function userPasswordChangeAction(Request $request): RedirectResponse|SuccessView|FormView

src/bundle/Controller/PasswordResetController.php

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,20 @@
3939

4040
class PasswordResetController extends Controller
4141
{
42-
private FormFactory $formFactory;
43-
44-
private UserService $userService;
45-
46-
private Environment $twig;
47-
48-
private ActionResultHandler $actionResultHandler;
49-
50-
private PermissionResolver $permissionResolver;
51-
52-
private ConfigResolverInterface $configResolver;
53-
54-
private NotificationServiceInterface $notificationService;
55-
5642
public function __construct(
57-
FormFactory $formFactory,
58-
UserService $userService,
59-
Environment $twig,
60-
ActionResultHandler $actionResultHandler,
61-
PermissionResolver $permissionResolver,
62-
ConfigResolverInterface $configResolver,
63-
NotificationServiceInterface $notificationService
43+
private readonly FormFactory $formFactory,
44+
private readonly UserService $userService,
45+
private readonly Environment $twig,
46+
private readonly ActionResultHandler $actionResultHandler,
47+
private readonly PermissionResolver $permissionResolver,
48+
private readonly ConfigResolverInterface $configResolver,
49+
private readonly NotificationServiceInterface $notificationService
6450
) {
65-
$this->formFactory = $formFactory;
66-
$this->userService = $userService;
67-
$this->twig = $twig;
68-
$this->actionResultHandler = $actionResultHandler;
69-
$this->permissionResolver = $permissionResolver;
70-
$this->configResolver = $configResolver;
71-
$this->notificationService = $notificationService;
7251
}
7352

7453
/**
75-
* @return \Ibexa\User\View\ForgotPassword\FormView|\Ibexa\User\View\ForgotPassword\SuccessView|\Symfony\Component\HttpFoundation\RedirectResponse
76-
*
7754
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
55+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
7856
*/
7957
public function userForgotPasswordAction(Request $request, ?string $reason = null): RedirectResponse|SuccessView|FormView
8058
{
@@ -108,11 +86,8 @@ public function userForgotPasswordAction(Request $request, ?string $reason = nul
10886
}
10987

11088
/**
111-
* @param \Symfony\Component\HttpFoundation\Request $request
112-
*
113-
* @return \Ibexa\User\View\ForgotPassword\LoginView|\Ibexa\User\View\ForgotPassword\SuccessView
114-
*
11589
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
90+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
11691
*/
11792
public function userForgotPasswordLoginAction(Request $request): SuccessView|LoginView
11893
{
@@ -125,7 +100,7 @@ public function userForgotPasswordLoginAction(Request $request): SuccessView|Log
125100

126101
try {
127102
$user = $this->userService->loadUserByLogin($data->getLogin());
128-
} catch (NotFoundException $e) {
103+
} catch (NotFoundException) {
129104
$user = null;
130105
}
131106

@@ -145,11 +120,6 @@ public function userForgotPasswordLoginAction(Request $request): SuccessView|Log
145120
}
146121

147122
/**
148-
* @param \Symfony\Component\HttpFoundation\Request $request
149-
* @param string $hashKey
150-
*
151-
* @return \Ibexa\User\View\ResetPassword\FormView|\Ibexa\User\View\ResetPassword\InvalidLinkView|\Ibexa\User\View\ResetPassword\SuccessView
152-
*
153123
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
154124
*/
155125
public function userResetPasswordAction(Request $request, string $hashKey): InvalidLinkView|UserResetPasswordSuccessView|UserResetPasswordFormView
@@ -210,10 +180,6 @@ public function userResetPasswordAction(Request $request, string $hashKey): Inva
210180
}
211181

212182
/**
213-
* @param \Ibexa\Contracts\Core\Repository\Values\User\User $user
214-
*
215-
* @return string
216-
*
217183
* @throws \Exception
218184
*/
219185
private function updateUserToken(User $user): string

src/bundle/Controller/UserInvitationController.php

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,21 @@ final class UserInvitationController extends Controller implements RestrictedCon
2626
{
2727
use AuthenticatedRememberedCheckTrait;
2828

29-
private InvitationService $invitationService;
30-
31-
private InvitationSender $mailSender;
32-
33-
private FormFactoryInterface $formFactory;
34-
35-
private ActionResultHandler $actionResultHandler;
36-
3729
public function __construct(
38-
InvitationService $invitationService,
39-
InvitationSender $mailSender,
40-
FormFactoryInterface $formFactory,
41-
ActionResultHandler $actionResultHandler
30+
private InvitationService $invitationService,
31+
private InvitationSender $mailSender,
32+
private FormFactoryInterface $formFactory,
33+
private ActionResultHandler $actionResultHandler
4234
) {
43-
$this->invitationService = $invitationService;
44-
$this->mailSender = $mailSender;
45-
$this->formFactory = $formFactory;
46-
$this->actionResultHandler = $actionResultHandler;
4735
}
4836

37+
/**
38+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
39+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
40+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
41+
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
42+
* @throws \JsonException
43+
*/
4944
public function inviteUser(Request $request): FormView
5045
{
5146
$form = $this->formFactory->create(UserInvitationType::class);
@@ -73,14 +68,14 @@ public function inviteUser(Request $request): FormView
7368
['%email%' => $data->getEmail()],
7469
'ibexa_user_invitation'
7570
);
76-
} catch (InvitationAlreadyExistsException $e) {
71+
} catch (InvitationAlreadyExistsException) {
7772
$this->actionResultHandler->error(
7873
/** @Desc("Invitation for '%email%' already exists.") */
7974
'user_invitation.send.invitation_exist',
8075
['%email%' => $data->getEmail()],
8176
'ibexa_user_invitation'
8277
);
83-
} catch (UserAlreadyExistsException $e) {
78+
} catch (UserAlreadyExistsException) {
8479
$this->actionResultHandler->error(
8580
/** @Desc("User with '%email%' already exists.") */
8681
'user_invitation.send.user_exist',

src/bundle/Controller/UserRegisterController.php

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,22 @@
1616
use Ibexa\User\View\Register\ConfirmView;
1717
use Ibexa\User\View\Register\FormView;
1818
use Symfony\Component\HttpFoundation\Request;
19+
use Symfony\Component\HttpFoundation\Response;
1920
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
2021

2122
class UserRegisterController extends Controller
2223
{
23-
private UserRegisterMapper $userRegisterMapper;
24-
25-
private ActionDispatcherInterface $userActionDispatcher;
26-
27-
private InvitationService $invitationService;
28-
2924
public function __construct(
30-
UserRegisterMapper $userRegisterMapper,
31-
ActionDispatcherInterface $userActionDispatcher,
32-
InvitationService $invitationService
25+
private readonly UserRegisterMapper $userRegisterMapper,
26+
private readonly ActionDispatcherInterface $userActionDispatcher,
27+
private readonly InvitationService $invitationService
3328
) {
34-
$this->userRegisterMapper = $userRegisterMapper;
35-
$this->userActionDispatcher = $userActionDispatcher;
36-
$this->invitationService = $invitationService;
3729
}
3830

3931
/**
40-
* @param \Symfony\Component\HttpFoundation\Request $request
41-
*
42-
* @return \Ibexa\User\View\Register\FormView|\Symfony\Component\HttpFoundation\Response|null
43-
*
4432
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
4533
*/
46-
public function registerAction(Request $request)
34+
public function registerAction(Request $request): Response|FormView
4735
{
4836
if (!$this->isGranted(new Attribute('user', 'register'))) {
4937
throw new UnauthorizedHttpException('You are not allowed to register a new account');
@@ -70,20 +58,12 @@ public function registerAction(Request $request)
7058
return new FormView(null, ['form' => $form->createView()]);
7159
}
7260

73-
/**
74-
* @return \Ibexa\User\View\Register\ConfirmView
75-
*
76-
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
77-
*/
7861
public function registerConfirmAction(): ConfirmView
7962
{
8063
return new ConfirmView();
8164
}
8265

83-
/**
84-
* @return \Ibexa\User\View\Register\FormView|\Symfony\Component\HttpFoundation\Response
85-
*/
86-
public function registerFromInvitationAction(Request $request)
66+
public function registerFromInvitationAction(Request $request): Response|FormView
8767
{
8868
$invitation = $this->invitationService->getInvitation($request->get('inviteHash'));
8969

src/bundle/Controller/UserSettingsController.php

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,19 @@ final class UserSettingsController extends Controller implements RestrictedContr
3030
{
3131
use AuthenticatedRememberedCheckTrait;
3232

33-
private FormFactory $formFactory;
34-
35-
private SubmitHandler $submitHandler;
36-
37-
private UserSettingService $userSettingService;
38-
39-
private ValueDefinitionRegistry $valueDefinitionRegistry;
40-
41-
private ActionResultHandler $actionResultHandler;
42-
43-
private PermissionResolver $permissionResolver;
44-
4533
public function __construct(
46-
FormFactory $formFactory,
47-
SubmitHandler $submitHandler,
48-
UserSettingService $userSettingService,
49-
ValueDefinitionRegistry $valueDefinitionRegistry,
50-
ActionResultHandler $actionResultHandler,
51-
PermissionResolver $permissionResolver
34+
private readonly FormFactory $formFactory,
35+
private readonly SubmitHandler $submitHandler,
36+
private readonly UserSettingService $userSettingService,
37+
private readonly ValueDefinitionRegistry $valueDefinitionRegistry,
38+
private readonly ActionResultHandler $actionResultHandler,
39+
private readonly PermissionResolver $permissionResolver
5240
) {
53-
$this->formFactory = $formFactory;
54-
$this->submitHandler = $submitHandler;
55-
$this->userSettingService = $userSettingService;
56-
$this->valueDefinitionRegistry = $valueDefinitionRegistry;
57-
$this->actionResultHandler = $actionResultHandler;
58-
$this->permissionResolver = $permissionResolver;
5941
}
6042

6143
/**
62-
* @param int $page
63-
*
64-
* @return \Ibexa\User\View\UserSettings\ListView
65-
*
44+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
45+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
6646
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
6747
*/
6848
public function listAction(int $page = 1): ListView

0 commit comments

Comments
 (0)