Skip to content

Commit e909007

Browse files
committed
PHPStan
1 parent c03d915 commit e909007

File tree

85 files changed

+418
-1393
lines changed

Some content is hidden

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

85 files changed

+418
-1393
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 758 deletions
Large diffs are not rendered by default.

src/bundle/Routing/OptionsLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function load(mixed $resource, $type = null)
3535
return $this->routeCollectionMapper->mapCollection($this->import($resource));
3636
}
3737

38-
public function supports($resource, $type = null): bool
38+
public function supports(mixed $resource, $type = null): bool
3939
{
4040
return $type === 'rest_options';
4141
}

src/lib/Server/Controller/Content/ContentCopyController.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,21 @@ class ContentCopyController extends RestController
1616
{
1717
/**
1818
* Creates a new content object as copy under the given parent location given in the destination header.
19-
*
20-
* @param mixed $contentId
21-
*
22-
* @return \Ibexa\Rest\Server\Values\ResourceCreated
2319
*/
24-
public function copyContent($contentId, Request $request)
20+
public function copyContent(int $contentId, Request $request): Values\ResourceCreated
2521
{
26-
$destination = $request->headers->get('Destination');
22+
$destination = (string)$request->headers->get('Destination');
2723

2824
$parentLocationParts = explode('/', $destination);
2925
$copiedContent = $this->repository->getContentService()->copyContent(
3026
$this->repository->getContentService()->loadContentInfo($contentId),
31-
$this->repository->getLocationService()->newLocationCreateStruct(array_pop($parentLocationParts))
27+
$this->repository->getLocationService()->newLocationCreateStruct((int)array_pop($parentLocationParts))
3228
);
3329

3430
return new Values\ResourceCreated(
3531
$this->router->generate(
3632
'ibexa.rest.load_content',
37-
['contentId' => $copiedContent->id]
33+
['contentId' => $copiedContent->id],
3834
)
3935
);
4036
}

src/lib/Server/Controller/Content/ContentCreateController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ApiPlatform\Metadata\Post;
1111
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
1212
use ApiPlatform\OpenApi\Model;
13+
use Ibexa\Contracts\Core\Repository\ContentService;
1314
use Ibexa\Contracts\Core\Repository\Exceptions\ContentFieldValidationException;
1415
use Ibexa\Contracts\Core\Repository\Exceptions\ContentValidationException;
1516
use Ibexa\Rest\Message;
@@ -103,6 +104,11 @@
103104
)]
104105
class ContentCreateController extends RestController
105106
{
107+
public function __construct(
108+
private readonly ContentService\RelationListFacadeInterface $relationListFacade
109+
) {
110+
}
111+
106112
/**
107113
* Creates a new content draft assigned to the authenticated user.
108114
* If a different userId is given in the input it is assigned to the
@@ -173,7 +179,7 @@ protected function doCreateContent(Request $request, RestContentCreateStruct $co
173179
$contentType = $this->repository->getContentTypeService()->loadContentType(
174180
$content->getVersionInfo()->getContentInfo()->contentTypeId
175181
);
176-
$relations = $this->repository->getContentService()->loadRelations($contentValue->getVersionInfo());
182+
$relations = iterator_to_array($this->relationListFacade->getRelations($contentValue->getVersionInfo()));
177183
}
178184

179185
return new Values\CreatedContent(

src/lib/Server/Controller/Content/ContentDraftCreateFromCurrentVersionController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ApiPlatform\Metadata\Post;
1111
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
1212
use ApiPlatform\OpenApi\Model;
13+
use Ibexa\Contracts\Core\Repository\ContentService;
1314
use Ibexa\Rest\Server\Controller as RestController;
1415
use Ibexa\Rest\Server\Exceptions\ForbiddenException;
1516
use Ibexa\Rest\Server\Values;
@@ -78,6 +79,11 @@
7879
)]
7980
class ContentDraftCreateFromCurrentVersionController extends RestController
8081
{
82+
public function __construct(
83+
private readonly ContentService\RelationListFacadeInterface $relationListFacade
84+
) {
85+
}
86+
8187
/**
8288
* The system creates a new draft version as a copy from the current version.
8389
*
@@ -106,7 +112,7 @@ public function createDraftFromCurrentVersion($contentId)
106112
'version' => new Values\Version(
107113
$contentDraft,
108114
$contentType,
109-
$this->repository->getContentService()->loadRelations($contentDraft->getVersionInfo())
115+
iterator_to_array($this->relationListFacade->getRelations($contentDraft->getVersionInfo())),
110116
),
111117
]
112118
);

src/lib/Server/Controller/Content/ContentDraftCreateFromVersionController.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use ApiPlatform\Metadata\Post;
1111
use ApiPlatform\OpenApi\Factory\OpenApiFactory;
1212
use ApiPlatform\OpenApi\Model;
13+
use Ibexa\Contracts\Core\Repository\ContentService;
1314
use Ibexa\Rest\Server\Controller as RestController;
1415
use Ibexa\Rest\Server\Values;
1516
use Symfony\Component\HttpFoundation\Response;
@@ -82,29 +83,31 @@
8283
)]
8384
class ContentDraftCreateFromVersionController extends RestController
8485
{
86+
public function __construct(
87+
private readonly ContentService\RelationListFacadeInterface $relationListFacade
88+
) {
89+
}
90+
8591
/**
8692
* The system creates a new draft version as a copy from the given version.
87-
*
88-
* @param mixed $contentId
89-
* @param mixed $versionNumber
90-
*
91-
* @return \Ibexa\Rest\Server\Values\CreatedVersion
9293
*/
93-
public function createDraftFromVersion($contentId, $versionNumber)
94+
public function createDraftFromVersion(int $contentId, int $versionNumber): Values\CreatedVersion
9495
{
95-
$contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
96+
$contentService = $this->repository->getContentService();
97+
98+
$contentInfo = $contentService->loadContentInfo($contentId);
9699
$contentType = $this->repository->getContentTypeService()->loadContentType($contentInfo->contentTypeId);
97-
$contentDraft = $this->repository->getContentService()->createContentDraft(
100+
$contentDraft = $contentService->createContentDraft(
98101
$contentInfo,
99-
$this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber)
102+
$contentService->loadVersionInfo($contentInfo, $versionNumber)
100103
);
101104

102105
return new Values\CreatedVersion(
103106
[
104107
'version' => new Values\Version(
105108
$contentDraft,
106109
$contentType,
107-
$this->repository->getContentService()->loadRelations($contentDraft->getVersionInfo())
110+
iterator_to_array($this->relationListFacade->getRelations($contentDraft->getVersionInfo())),
108111
),
109112
]
110113
);

src/lib/Server/Controller/Content/ContentInVersionLoadController.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
use ApiPlatform\Metadata\Get;
1111
use ApiPlatform\OpenApi\Model;
12+
use Ibexa\Contracts\Core\Repository\ContentService;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
1314
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
1415
use Ibexa\Rest\Server\Controller as RestController;
1516
use Ibexa\Rest\Server\Values;
17+
use Ibexa\Rest\Server\Values\Version;
1618
use Symfony\Component\HttpFoundation\Request;
1719
use Symfony\Component\HttpFoundation\Response;
1820

@@ -91,19 +93,22 @@
9193
)]
9294
class ContentInVersionLoadController extends RestController
9395
{
96+
public function __construct(
97+
private readonly ContentService\RelationListFacadeInterface $relationListFacade
98+
) {
99+
}
100+
94101
/**
95102
* Loads a specific version of a given content object.
96-
*
97-
* @param mixed $contentId
98-
* @param int $versionNumber
99-
*
100-
* @return \Ibexa\Rest\Server\Values\Version
101103
*/
102-
public function loadContentInVersion($contentId, $versionNumber, Request $request)
103-
{
104+
public function loadContentInVersion(
105+
int $contentId,
106+
int $versionNumber,
107+
Request $request
108+
): Version|Values\CachedValue {
104109
$languages = Language::ALL;
105110
if ($request->query->has('languages')) {
106-
$languages = explode(',', $request->query->get('languages'));
111+
$languages = explode(',', $request->query->getString('languages'));
107112
}
108113

109114
$content = $this->repository->getContentService()->loadContent(
@@ -115,10 +120,10 @@ public function loadContentInVersion($contentId, $versionNumber, Request $reques
115120
$content->getVersionInfo()->getContentInfo()->contentTypeId
116121
);
117122

118-
$versionValue = new Values\Version(
123+
$versionValue = new Version(
119124
$content,
120125
$contentType,
121-
$this->repository->getContentService()->loadRelations($content->getVersionInfo()),
126+
iterator_to_array($this->relationListFacade->getRelations($content->getVersionInfo())),
122127
$request->getPathInfo()
123128
);
124129

src/lib/Server/Controller/Content/ContentLoadByIdController.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use ApiPlatform\Metadata\Get;
1111
use ApiPlatform\OpenApi\Model;
12+
use Ibexa\Contracts\Core\Repository\ContentService;
1213
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
1314
use Ibexa\Rest\Server\Controller as RestController;
1415
use Ibexa\Rest\Server\Values;
@@ -90,17 +91,19 @@
9091
)]
9192
class ContentLoadByIdController extends RestController
9293
{
94+
public function __construct(
95+
private readonly ContentService\RelationListFacadeInterface $relationListFacade
96+
) {
97+
}
98+
9399
/**
94100
* Loads a content info, potentially with the current version embedded.
95-
*
96-
* @param mixed $contentId
97-
* @param \Symfony\Component\HttpFoundation\Request $request
98-
*
99-
* @return \Ibexa\Rest\Server\Values\RestContent
100101
*/
101-
public function loadContent($contentId, Request $request)
102+
public function loadContent(int $contentId, Request $request): Values\CachedValue|Values\RestContent
102103
{
103-
$contentInfo = $this->repository->getContentService()->loadContentInfo($contentId);
104+
$contentService = $this->repository->getContentService();
105+
106+
$contentInfo = $contentService->loadContentInfo($contentId);
104107

105108
$mainLocation = null;
106109
if (!empty($contentInfo->mainLocationId)) {
@@ -114,11 +117,11 @@ public function loadContent($contentId, Request $request)
114117
if ($this->getMediaType($request) === 'application/vnd.ibexa.api.content') {
115118
$languages = Language::ALL;
116119
if ($request->query->has('languages')) {
117-
$languages = explode(',', $request->query->get('languages'));
120+
$languages = explode(',', $request->query->getString('languages'));
118121
}
119122

120-
$contentVersion = $this->repository->getContentService()->loadContent($contentId, $languages);
121-
$relations = $this->repository->getContentService()->loadRelations($contentVersion->getVersionInfo());
123+
$contentVersion = $contentService->loadContent($contentId, $languages);
124+
$relations = iterator_to_array($this->relationListFacade->getRelations($contentVersion->getVersionInfo()));
122125
}
123126

124127
$restContent = new Values\RestContent(

src/lib/Server/Controller/Content/ContentMetadataUpdateController.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Ibexa\Rest\Message;
1515
use Ibexa\Rest\Server\Controller as RestController;
1616
use Ibexa\Rest\Server\Values;
17+
use LogicException;
1718
use Symfony\Component\HttpFoundation\Request;
1819
use Symfony\Component\HttpFoundation\Response;
1920

@@ -116,12 +117,8 @@ class ContentMetadataUpdateController extends RestController
116117
{
117118
/**
118119
* Updates a content's metadata.
119-
*
120-
* @param mixed $contentId
121-
*
122-
* @return \Ibexa\Rest\Server\Values\RestContent
123120
*/
124-
public function updateContentMetadata($contentId, Request $request)
121+
public function updateContentMetadata(int $contentId, Request $request): Values\RestContent
125122
{
126123
$updateStruct = $this->inputDispatcher->parse(
127124
new Message(
@@ -152,6 +149,10 @@ public function updateContentMetadata($contentId, Request $request)
152149
}
153150
}
154151

152+
if ($contentInfo->mainLocationId === null) {
153+
throw new LogicException();
154+
}
155+
155156
try {
156157
$locationInfo = $this->repository->getLocationService()->loadLocation($contentInfo->mainLocationId);
157158
} catch (NotFoundException $e) {

src/lib/Server/Controller/Content/ContentRedirectController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function redirectContent(Request $request)
5454
}
5555

5656
$contentInfo = $this->repository->getContentService()->loadContentInfoByRemoteId(
57-
$request->query->get('remoteId')
57+
$request->query->getString('remoteId')
5858
);
5959

6060
return new Values\TemporaryRedirect(

0 commit comments

Comments
 (0)