Skip to content

Commit 497360a

Browse files
committed
IBX-9727: Added type-hints and adapted codebase to PHP8+
1 parent 8f4f37c commit 497360a

File tree

163 files changed

+821
-1878
lines changed

Some content is hidden

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

163 files changed

+821
-1878
lines changed

.php-cs-fixer.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@
88

99
use Ibexa\CodeStyle\PhpCsFixer\InternalConfigFactory;
1010

11-
$configFactory = new InternalConfigFactory();
12-
$configFactory->withRules([
13-
'declare_strict_types' => false,
14-
]);
15-
16-
return $configFactory
17-
->buildConfig()
18-
->setFinder(
19-
PhpCsFixer\Finder::create()
20-
->in([
21-
__DIR__ . '/src',
22-
__DIR__ . '/tests',
23-
])
24-
->files()->name('*.php')
11+
return (new InternalConfigFactory())->buildConfig()->setFinder(
12+
PhpCsFixer\Finder::create()
13+
->in([
14+
__DIR__ . '/src',
15+
__DIR__ . '/tests',
16+
])
17+
->files()->name('*.php')
2518
);

phpstan-baseline.neon

Lines changed: 29 additions & 347 deletions
Large diffs are not rendered by default.

src/bundle/Controller/ContentEditController.php

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,31 @@
2020
use Ibexa\Contracts\Core\Repository\ContentService;
2121
use Ibexa\Contracts\Core\Repository\ContentTypeService;
2222
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\HttpFoundation\Response;
2324

24-
class ContentEditController extends Controller
25+
final class ContentEditController extends Controller
2526
{
26-
private ContentTypeService $contentTypeService;
27-
28-
private ContentService $contentService;
29-
30-
private ActionDispatcherInterface $contentActionDispatcher;
31-
3227
public function __construct(
33-
ContentTypeService $contentTypeService,
34-
ContentService $contentService,
35-
ActionDispatcherInterface $contentActionDispatcher
28+
private readonly ContentTypeService $contentTypeService,
29+
private readonly ContentService $contentService,
30+
private readonly ActionDispatcherInterface $contentActionDispatcher
3631
) {
37-
$this->contentTypeService = $contentTypeService;
38-
$this->contentService = $contentService;
39-
$this->contentActionDispatcher = $contentActionDispatcher;
4032
}
4133

4234
/**
4335
* Displays and processes a content creation form. Showing the form does not create a draft in the repository.
44-
*
45-
* @param \Ibexa\ContentForms\Content\View\ContentCreateView $view
46-
*
47-
* @return \Ibexa\ContentForms\Content\View\ContentCreateView
4836
*/
4937
public function createWithoutDraftAction(ContentCreateView $view): ContentCreateView
5038
{
5139
return $view;
5240
}
5341

54-
/**
55-
* @param \Ibexa\ContentForms\Content\View\ContentCreateSuccessView $view
56-
*
57-
* @return \Ibexa\ContentForms\Content\View\ContentCreateSuccessView
58-
*
59-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
60-
*/
6142
public function createWithoutDraftSuccessAction(ContentCreateSuccessView $view): ContentCreateSuccessView
6243
{
6344
return $view;
6445
}
6546

6647
/**
67-
* Displays a draft creation form that creates a content draft from an existing content.
68-
*
69-
* @param \Symfony\Component\HttpFoundation\Request $request
70-
* @param int|null $contentId
71-
* @param int $fromVersionNo
72-
* @param string $fromLanguage
73-
*
74-
* @return \Ibexa\ContentForms\Content\View\ContentCreateDraftView|\Symfony\Component\HttpFoundation\Response
75-
*
7648
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
7749
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
7850
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
@@ -82,7 +54,7 @@ public function createContentDraftAction(
8254
?int $contentId = null,
8355
?int $fromVersionNo = null,
8456
?string $fromLanguage = null
85-
) {
57+
): ContentCreateDraftView|Response {
8658
$createContentDraft = new CreateContentDraftData();
8759
$contentInfo = null;
8860
$contentType = null;
@@ -93,7 +65,7 @@ public function createContentDraftAction(
9365
$contentInfo = $this->contentService->loadContentInfo($contentId);
9466
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
9567
$createContentDraft->fromVersionNo = $fromVersionNo ?: $contentInfo->currentVersionNo;
96-
$createContentDraft->fromLanguage = $fromLanguage ?: $contentInfo->mainLanguageCode;
68+
$createContentDraft->fromLanguage = $fromLanguage ?: $contentInfo->getMainLanguageCode();
9769
}
9870

9971
$form = $this->createForm(
@@ -120,25 +92,11 @@ public function createContentDraftAction(
12092
]);
12193
}
12294

123-
/**
124-
* @param \Ibexa\ContentForms\Content\View\ContentEditView $view
125-
*
126-
* @return \Ibexa\ContentForms\Content\View\ContentEditView
127-
*
128-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
129-
*/
13095
public function editVersionDraftAction(ContentEditView $view): ContentEditView
13196
{
13297
return $view;
13398
}
13499

135-
/**
136-
* @param \Ibexa\ContentForms\Content\View\ContentEditSuccessView $view
137-
*
138-
* @return \Ibexa\ContentForms\Content\View\ContentEditSuccessView
139-
*
140-
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
141-
*/
142100
public function editVersionDraftSuccessAction(ContentEditSuccessView $view): ContentEditSuccessView
143101
{
144102
return $view;

src/bundle/Controller/UserController.php

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,24 @@
2727
use Ibexa\Core\Base\Exceptions\UnauthorizedException as CoreUnauthorizedException;
2828
use Ibexa\Core\MVC\Symfony\Locale\UserLanguagePreferenceProviderInterface;
2929
use Symfony\Component\HttpFoundation\Request;
30+
use Symfony\Component\HttpFoundation\Response;
3031

31-
class UserController extends Controller
32+
final class UserController extends Controller
3233
{
33-
private ContentTypeService $contentTypeService;
34-
35-
private UserService $userService;
36-
37-
private LocationService $locationService;
38-
39-
private LanguageService $languageService;
40-
41-
private ActionDispatcherInterface $userActionDispatcher;
42-
43-
private PermissionResolver $permissionResolver;
44-
45-
private UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider;
46-
47-
private GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider;
48-
49-
private ContentService $contentService;
50-
5134
public function __construct(
52-
ContentTypeService $contentTypeService,
53-
UserService $userService,
54-
LocationService $locationService,
55-
LanguageService $languageService,
56-
ActionDispatcherInterface $userActionDispatcher,
57-
PermissionResolver $permissionResolver,
58-
UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider,
59-
GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider,
60-
ContentService $contentService
35+
private readonly ContentTypeService $contentTypeService,
36+
private readonly UserService $userService,
37+
private readonly LocationService $locationService,
38+
private readonly LanguageService $languageService,
39+
private readonly ActionDispatcherInterface $userActionDispatcher,
40+
private readonly PermissionResolver $permissionResolver,
41+
private readonly UserLanguagePreferenceProviderInterface $userLanguagePreferenceProvider,
42+
private readonly GroupedContentFormFieldsProviderInterface $groupedContentFormFieldsProvider,
43+
private readonly ContentService $contentService
6144
) {
62-
$this->contentTypeService = $contentTypeService;
63-
$this->userService = $userService;
64-
$this->locationService = $locationService;
65-
$this->languageService = $languageService;
66-
$this->userActionDispatcher = $userActionDispatcher;
67-
$this->permissionResolver = $permissionResolver;
68-
$this->userLanguagePreferenceProvider = $userLanguagePreferenceProvider;
69-
$this->groupedContentFormFieldsProvider = $groupedContentFormFieldsProvider;
70-
$this->contentService = $contentService;
7145
}
7246

7347
/**
74-
* Displays and processes a user creation form.
75-
*
76-
* @param string $contentTypeIdentifier ContentType id to create
77-
* @param string $language Language code to create the content in (eng-GB, ger-DE, ...))
78-
* @param int $parentLocationId Location the content should be a child of
79-
* @param \Symfony\Component\HttpFoundation\Request $request
80-
*
81-
* @return \Symfony\Component\HttpFoundation\Response|\Ibexa\ContentForms\User\View\UserCreateView
82-
*
8348
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType
8449
* @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentException
8550
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
@@ -96,21 +61,22 @@ public function createAction(
9661
string $language,
9762
int $parentLocationId,
9863
Request $request
99-
) {
64+
): Response|UserCreateView {
10065
$contentType = $this->contentTypeService->loadContentTypeByIdentifier(
10166
$contentTypeIdentifier,
10267
$this->userLanguagePreferenceProvider->getPreferredLanguages()
10368
);
10469
$location = $this->locationService->loadLocation($parentLocationId);
10570
$language = $this->languageService->loadLanguage($language);
106-
$parentGroup = $this->userService->loadUserGroup($location->contentId);
71+
$languageCode = $language->getLanguageCode();
72+
$parentGroup = $this->userService->loadUserGroup($location->getContentId());
10773

10874
$data = (new UserCreateMapper())->mapToFormData($contentType, [$parentGroup], [
109-
'mainLanguageCode' => $language->languageCode,
75+
'mainLanguageCode' => $languageCode,
11076
]);
11177
$form = $this->createForm(UserCreateType::class, $data, [
112-
'languageCode' => $language->languageCode,
113-
'mainLanguageCode' => $language->languageCode,
78+
'languageCode' => $languageCode,
79+
'mainLanguageCode' => $languageCode,
11480
'struct' => $data,
11581
]);
11682
$form->handleRequest($request);
@@ -138,15 +104,6 @@ public function createAction(
138104
}
139105

140106
/**
141-
* Displays a user update form that updates user data and related content item.
142-
*
143-
* @param int $contentId ContentType id to create
144-
* @param int $versionNo Version number the version should be created from. Defaults to the currently published one.
145-
* @param string $language Language code to create the version in (eng-GB, ger-DE, ...))
146-
* @param \Symfony\Component\HttpFoundation\Request $request
147-
*
148-
* @return \Symfony\Component\HttpFoundation\Response|\Ibexa\ContentForms\User\View\UserUpdateView
149-
*
150107
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException
151108
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\InvalidArgumentException
152109
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
@@ -159,13 +116,13 @@ public function editAction(
159116
int $versionNo,
160117
string $language,
161118
Request $request
162-
) {
119+
): Response|UserUpdateView {
163120
$user = $this->userService->loadUser($contentId);
164121
if (!$this->permissionResolver->canUser('content', 'edit', $user)) {
165122
throw new CoreUnauthorizedException('content', 'edit', ['userId' => $contentId]);
166123
}
167124
$contentType = $this->contentTypeService->loadContentType(
168-
$user->contentInfo->contentTypeId,
125+
$user->getContentInfo()->getContentType()->id,
169126
$this->userLanguagePreferenceProvider->getPreferredLanguages()
170127
);
171128

@@ -176,12 +133,12 @@ public function editAction(
176133
try {
177134
// assume main location if no location was provided
178135
$location = $this->locationService->loadLocation(
179-
(int)$user->versionInfo->contentInfo->mainLocationId
136+
(int)$user->getVersionInfo()->getContentInfo()->getMainLocationId()
180137
);
181138
} catch (UnauthorizedException $e) {
182139
// if no access to the main location assume content has multiple locations and first of them can be used
183140
$availableLocations = $this->locationService->loadLocations(
184-
$user->versionInfo->contentInfo
141+
$user->getVersionInfo()->getContentInfo()
185142
);
186143
$location = array_shift($availableLocations);
187144
}
@@ -193,7 +150,7 @@ public function editAction(
193150
'location' => $location,
194151
'content' => $this->contentService->loadContent($contentId),
195152
'languageCode' => $language,
196-
'mainLanguageCode' => $user->contentInfo->mainLanguageCode,
153+
'mainLanguageCode' => $user->getContentInfo()->getMainLanguageCode(),
197154
'struct' => $userUpdate,
198155
],
199156
);
@@ -209,7 +166,8 @@ public function editAction(
209166
$parentLocation = null;
210167
try {
211168
$parentLocation = $this->locationService->loadLocation($location->parentLocationId);
212-
} catch (UnauthorizedException $e) {
169+
} catch (UnauthorizedException) {
170+
//do nothing
213171
}
214172

215173
return new UserUpdateView(

src/bundle/DependencyInjection/Compiler/FieldTypeFormMapperDispatcherPass.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Reference;
1616

17-
/**
18-
* Compiler pass to register FieldType form mappers in the mapper dispatcher.
19-
*/
20-
class FieldTypeFormMapperDispatcherPass implements CompilerPassInterface
17+
final class FieldTypeFormMapperDispatcherPass implements CompilerPassInterface
2118
{
2219
public const string FIELD_TYPE_FORM_MAPPER_DISPATCHER = FieldTypeFormMapperDispatcher::class;
2320
public const string FIELD_TYPE_FORM_MAPPER_VALUE_SERVICE_TAG = 'ibexa.admin_ui.field_type.form.mapper.value';
@@ -46,7 +43,10 @@ public function process(ContainerBuilder $container): void
4643
);
4744
}
4845

49-
$dispatcherDefinition->addMethodCall('addMapper', [new Reference($serviceId), $tag['fieldType']]);
46+
$dispatcherDefinition->addMethodCall(
47+
'addMapper',
48+
[new Reference($serviceId), $tag['fieldType']]
49+
);
5050
}
5151
}
5252
}

src/bundle/DependencyInjection/Configuration/Parser/ContentCreateView.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
use Ibexa\Bundle\Core\DependencyInjection\Configuration\Parser\View;
1212

13-
class ContentCreateView extends View
13+
final class ContentCreateView extends View
1414
{
15-
public const NODE_KEY = 'content_create_view';
16-
public const INFO = 'Template selection settings when displaying a content create form';
15+
public const string NODE_KEY = 'content_create_view';
16+
public const string INFO = 'Template selection settings when displaying a content create form';
1717
}

0 commit comments

Comments
 (0)