Skip to content

Commit bb41306

Browse files
committed
Fix issues reported by PHPStan
1 parent c78a111 commit bb41306

14 files changed

Lines changed: 109 additions & 100 deletions

File tree

bundle/API/Repository/Values/Tags/TagStruct.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public function getKeywords(): array
4949
*/
5050
public function getKeyword(?string $language = null): ?string
5151
{
52-
return $this->keywords[$language ?? $this->mainLanguageCode] ?? null;
52+
return $this->keywords[$language ?? $this->mainLanguageCode ?? ''] ?? null;
5353
}
5454

5555
/**
5656
* Adds a keyword to keyword collection.
5757
*/
5858
public function setKeyword(string $keyword, ?string $language = null): void
5959
{
60-
$this->keywords[$language ?? $this->mainLanguageCode] = $keyword;
60+
$this->keywords[$language ?? $this->mainLanguageCode ?? ''] = $keyword;
6161
}
6262

6363
/**

bundle/Controller/Admin/TagController.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,10 @@ public function moveTagsAction(Request $request, ?Tag $parentTag = null): Respon
513513
{
514514
$this->denyAccessUnlessGranted('ibexa:tags:edit');
515515

516-
$tagIds = (array) $request->request->get('Tags', $request->hasSession() ? $request->getSession()->get('ngtags_tag_ids') : []);
516+
$tagIds = $request->hasSession() ? $request->getSession()->get('ngtags_tag_ids') : [];
517+
if ($request->request->has('Tags')) {
518+
$tagIds = $request->request->all('Tags');
519+
}
517520

518521
if (count($tagIds) === 0) {
519522
return $this->redirectToTag($parentTag);
@@ -572,7 +575,10 @@ public function copyTagsAction(Request $request, ?Tag $parentTag = null): Respon
572575
{
573576
$this->denyAccessUnlessGranted('ibexa:tags:read');
574577

575-
$tagIds = (array) $request->request->get('Tags', $request->hasSession() ? $request->getSession()->get('ngtags_tag_ids') : []);
578+
$tagIds = $request->hasSession() ? $request->getSession()->get('ngtags_tag_ids') : [];
579+
if ($request->request->has('Tags')) {
580+
$tagIds = $request->request->all('Tags');
581+
}
576582

577583
if (count($tagIds) === 0) {
578584
return $this->redirectToTag($parentTag);
@@ -631,7 +637,10 @@ public function deleteTagsAction(Request $request, ?Tag $parentTag = null): Resp
631637
{
632638
$this->denyAccessUnlessGranted('ibexa:tags:delete');
633639

634-
$tagIds = (array) $request->request->get('Tags', $request->hasSession() ? $request->getSession()->get('ngtags_tag_ids') : []);
640+
$tagIds = $request->hasSession() ? $request->getSession()->get('ngtags_tag_ids') : [];
641+
if ($request->request->has('Tags')) {
642+
$tagIds = $request->request->all('Tags');
643+
}
635644

636645
if (count($tagIds) === 0) {
637646
return $this->redirectToTag($parentTag);

bundle/Core/Persistence/Legacy/Tags/Gateway/DoctrineDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ public function update(UpdateStruct $updateStruct, int $tagId): void
456456
),
457457
)->setParameter('id', $tagId, Types::INTEGER)
458458
->setParameter('modified', time(), Types::INTEGER)
459-
->setParameter('keyword', $updateStruct->keywords[$updateStruct->mainLanguageCode] ?? '', Types::STRING)
459+
->setParameter('keyword', $updateStruct->keywords[$updateStruct->mainLanguageCode ?? ''] ?? '', Types::STRING)
460460
->setParameter('remote_id', $updateStruct->remoteId, Types::STRING)
461461
->setParameter(
462462
'main_language_id',

bundle/Form/Type/RelatedContentFilterType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private function getAllContentTypeOptions(): array
120120
$groupOptions = [];
121121

122122
foreach ($contentTypes as $contentType) {
123-
$groupOptions[$contentType->getName()] = $contentType->identifier;
123+
$groupOptions[$contentType->getName() ?? ''] = $contentType->identifier;
124124
}
125125

126126
$options[$group->identifier] = $groupOptions;

bundle/Matcher/Tag/Keyword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function match(View $view): bool
1515
return false;
1616
}
1717

18-
return isset($this->values[$view->getTag()->getKeyword()]);
18+
return isset($this->values[$view->getTag()->getKeyword() ?? '']);
1919
}
2020
}

bundle/Matcher/Tag/ParentKeyword.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function match(View $view): bool
2323
static fn (TagsService $tagsService): Tag => $tagsService->loadTag($tag->parentTagId),
2424
);
2525

26-
return isset($this->values[$parentTag->getKeyword()]);
26+
return isset($this->values[$parentTag->getKeyword() ?? '']);
2727
}
2828
}

tests/API/Repository/FieldType/TagsIntegrationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function assertFieldDataLoadedCorrect(Field $field): void
102102
self::assertContainsEquals($this->getTag1(), $field->value->tags);
103103
}
104104

105-
public function provideInvalidCreationFieldData(): iterable
105+
public function provideInvalidCreationFieldData(): array
106106
{
107107
return [
108108
[
@@ -148,7 +148,7 @@ public function assertUpdatedFieldDataLoadedCorrect(Field $field): void
148148
self::assertContainsEquals($this->getTag3(), $field->value->tags);
149149
}
150150

151-
public function provideInvalidUpdateFieldData(): iterable
151+
public function provideInvalidUpdateFieldData(): array
152152
{
153153
return $this->provideInvalidCreationFieldData();
154154
}
@@ -164,7 +164,7 @@ public function assertCopiedFieldDataLoadedCorrectly(Field $field): void
164164
self::assertContainsEquals($this->getTag1(), $field->value->tags);
165165
}
166166

167-
public function provideToHashData(): iterable
167+
public function provideToHashData(): array
168168
{
169169
return [
170170
[
@@ -188,7 +188,7 @@ public function provideToHashData(): iterable
188188
];
189189
}
190190

191-
public function provideFromHashData(): iterable
191+
public function provideFromHashData(): array
192192
{
193193
return [
194194
[

tests/Core/Event/TagsServiceTest.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected function setUp(): void
3737
public function testLoadTag(): void
3838
{
3939
$this->tagsService
40-
->expects($this->once())
40+
->expects(self::once())
4141
->method('loadTag')
4242
->with(self::identicalTo(42))
4343
->willReturn(new Tag(['id' => 42]));
@@ -54,7 +54,7 @@ public function testLoadTag(): void
5454
public function testLoadTagByRemoteId(): void
5555
{
5656
$this->tagsService
57-
->expects($this->once())
57+
->expects(self::once())
5858
->method('loadTagByRemoteId')
5959
->with(self::identicalTo('12345'))
6060
->willReturn(new Tag(['remoteId' => '12345']));
@@ -71,7 +71,7 @@ public function testLoadTagByRemoteId(): void
7171
public function testLoadTagByUrl(): void
7272
{
7373
$this->tagsService
74-
->expects($this->once())
74+
->expects(self::once())
7575
->method('loadTagByUrl')
7676
->with('Netgen/TagsBundle', ['eng-GB'])
7777
->willReturn(new Tag(['keywords' => ['eng-GB' => 'TagsBundle']]));
@@ -90,7 +90,7 @@ public function testLoadTagChildren(): void
9090
$tag = new Tag(['id' => 42]);
9191

9292
$this->tagsService
93-
->expects($this->once())
93+
->expects(self::once())
9494
->method('loadTagChildren')
9595
->with(self::identicalTo($tag))
9696
->willReturn(
@@ -121,7 +121,7 @@ public function testGetTagChildrenCount(): void
121121
$tag = new Tag(['id' => 42]);
122122

123123
$this->tagsService
124-
->expects($this->once())
124+
->expects(self::once())
125125
->method('getTagChildrenCount')
126126
->with(self::identicalTo($tag))
127127
->willReturn(2);
@@ -138,7 +138,7 @@ public function testGetTagChildrenCount(): void
138138
public function testLoadTagsByKeyword(): void
139139
{
140140
$this->tagsService
141-
->expects($this->once())
141+
->expects(self::once())
142142
->method('loadTagsByKeyword')
143143
->with('netgen', 'eng-GB')
144144
->willReturn(
@@ -167,7 +167,7 @@ public function testLoadTagsByKeyword(): void
167167
public function testGetTagsByKeywordCount(): void
168168
{
169169
$this->tagsService
170-
->expects($this->once())
170+
->expects(self::once())
171171
->method('getTagsByKeywordCount')
172172
->with('netgen', 'eng-GB')
173173
->willReturn(2);
@@ -186,7 +186,7 @@ public function testLoadTagSynonyms(): void
186186
$tag = new Tag(['id' => 42]);
187187

188188
$this->tagsService
189-
->expects($this->once())
189+
->expects(self::once())
190190
->method('loadTagSynonyms')
191191
->with(self::identicalTo($tag))
192192
->willReturn(
@@ -217,7 +217,7 @@ public function testGetTagSynonymCount(): void
217217
$tag = new Tag(['id' => 42]);
218218

219219
$this->tagsService
220-
->expects($this->once())
220+
->expects(self::once())
221221
->method('getTagSynonymCount')
222222
->with(self::identicalTo($tag))
223223
->willReturn(2);
@@ -236,7 +236,7 @@ public function testGetRelatedContent(): void
236236
$tag = new Tag(['id' => 42]);
237237

238238
$this->tagsService
239-
->expects($this->once())
239+
->expects(self::once())
240240
->method('getRelatedContent')
241241
->with(self::identicalTo($tag))
242242
->willReturn([new Content(), new Content()]);
@@ -256,7 +256,7 @@ public function testGetRelatedContentCount(): void
256256
$tag = new Tag(['id' => 42]);
257257

258258
$this->tagsService
259-
->expects($this->once())
259+
->expects(self::once())
260260
->method('getRelatedContentCount')
261261
->with(self::identicalTo($tag))
262262
->willReturn(2);
@@ -289,7 +289,7 @@ public function testCreateTag(): void
289289
);
290290

291291
$this->tagsService
292-
->expects($this->once())
292+
->expects(self::once())
293293
->method('createTag')
294294
->with(self::identicalTo($tagCreateStruct))
295295
->willReturn($tag);
@@ -342,7 +342,7 @@ public function testUpdateTag(): void
342342
);
343343

344344
$this->tagsService
345-
->expects($this->once())
345+
->expects(self::once())
346346
->method('updateTag')
347347
->with(
348348
self::identicalTo($tag),
@@ -389,7 +389,7 @@ public function testAddSynonym(): void
389389
);
390390

391391
$this->tagsService
392-
->expects($this->once())
392+
->expects(self::once())
393393
->method('addSynonym')
394394
->with(self::identicalTo($synonymCreateStruct))
395395
->willReturn($synonym);
@@ -436,7 +436,7 @@ public function testConvertToSynonym(): void
436436
);
437437

438438
$this->tagsService
439-
->expects($this->once())
439+
->expects(self::once())
440440
->method('convertToSynonym')
441441
->with(
442442
self::identicalTo($tag),
@@ -476,7 +476,7 @@ public function testMergeTags(): void
476476
);
477477

478478
$this->tagsService
479-
->expects($this->once())
479+
->expects(self::once())
480480
->method('mergeTags')
481481
->with(
482482
self::identicalTo($tag),
@@ -521,7 +521,7 @@ public function testCopySubtree(): void
521521
);
522522

523523
$this->tagsService
524-
->expects($this->once())
524+
->expects(self::once())
525525
->method('copySubtree')
526526
->with(
527527
self::identicalTo($tag),
@@ -569,7 +569,7 @@ public function testMoveSubtree(): void
569569
);
570570

571571
$this->tagsService
572-
->expects($this->once())
572+
->expects(self::once())
573573
->method('moveSubtree')
574574
->with(
575575
self::identicalTo($tag),
@@ -603,7 +603,7 @@ public function testDeleteTag(): void
603603
);
604604

605605
$this->tagsService
606-
->expects($this->once())
606+
->expects(self::once())
607607
->method('deleteTag')
608608
->with(self::identicalTo($tag));
609609

@@ -624,7 +624,7 @@ public function testDeleteTag(): void
624624
public function testNewTagCreateStruct(): void
625625
{
626626
$this->tagsService
627-
->expects($this->once())
627+
->expects(self::once())
628628
->method('newTagCreateStruct')
629629
->with(self::identicalTo(42), self::identicalTo('eng-GB'))
630630
->willReturn(new TagCreateStruct(['parentTagId' => 42, 'mainLanguageCode' => 'eng-GB']));
@@ -642,7 +642,7 @@ public function testNewTagCreateStruct(): void
642642
public function testNewSynonymCreateStruct(): void
643643
{
644644
$this->tagsService
645-
->expects($this->once())
645+
->expects(self::once())
646646
->method('newSynonymCreateStruct')
647647
->with(self::identicalTo(42), self::identicalTo('eng-GB'))
648648
->willReturn(new SynonymCreateStruct(['mainTagId' => 42, 'mainLanguageCode' => 'eng-GB']));
@@ -660,7 +660,7 @@ public function testNewSynonymCreateStruct(): void
660660
public function testNewTagUpdateStruct(): void
661661
{
662662
$this->tagsService
663-
->expects($this->once())
663+
->expects(self::once())
664664
->method('newTagUpdateStruct')
665665
->willReturn(new TagUpdateStruct());
666666

@@ -678,7 +678,7 @@ public function testSudo(): void
678678
$callback = static function (): string { return 'some_value'; };
679679

680680
$this->tagsService
681-
->expects($this->once())
681+
->expects(self::once())
682682
->method('sudo')
683683
->willReturn($callback());
684684

tests/Core/Limitation/TagLimitationTypeTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,20 @@ public function testValidate(TagLimitation $limitation, int $errorCount): void
140140

141141
if (is_int($value)) {
142142
$this->tagsHandlerMock
143-
->expects($this->once())
143+
->expects(self::once())
144144
->method('loadTagInfo')
145145
->with($value)
146146
->willReturn(new TagInfo(['id' => $value]));
147147
} else {
148148
$this->tagsHandlerMock
149-
->expects($this->once())
149+
->expects(self::once())
150150
->method('loadTagInfo')
151151
->with($value)
152152
->willThrowException(new NotFoundException('tag', $value));
153153
}
154154
} else {
155155
$this->tagsHandlerMock
156-
->expects($this->never())
156+
->expects(self::never())
157157
->method(self::anything());
158158
}
159159

@@ -223,7 +223,7 @@ public function testBuildValue(): void
223223
public function testEvaluate(TagLimitation $limitation, ValueObject $object, mixed $expected): void
224224
{
225225
$this->userMock
226-
->expects($this->never())
226+
->expects(self::never())
227227
->method(self::anything());
228228

229229
$value = $this->limitationType->evaluate($limitation, $this->userMock, $object);
@@ -263,7 +263,7 @@ public function testEvaluateInvalidArgument(Limitation $limitation, ValueObject
263263
$this->expectException(InvalidArgumentException::class);
264264

265265
$this->userMock
266-
->expects($this->never())
266+
->expects(self::never())
267267
->method(self::anything());
268268

269269
$this->limitationType->evaluate($limitation, $this->userMock, $object);

0 commit comments

Comments
 (0)