Skip to content

Commit 6246e63

Browse files
alongoszadamwojs
andauthored
IBX-9727: Added missing type hints (#38)
* [Composer] Bumped PHPStan to ^2.0 * [Rector] Applied SetList::TYPE_DECLARATION built-in Rector set Applied Rectors: * Rector\TypeDeclaration\Rector\ClassMethod\AddMethodCallBasedStrictParamTypeRector * Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector * Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector * Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeRector * Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector * Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector * [PHPStan] Fixed phpstan issues --------- Co-authored-by: Adam Wójs <[email protected]>
1 parent ec3a0ff commit 6246e63

22 files changed

+139
-148
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
"ibexa/search": "~5.0.x-dev",
4949
"ibexa/user": "~5.0.x-dev",
5050
"phpspec/phpspec": "^7.1",
51-
"phpstan/phpstan": "^1.12",
52-
"phpstan/phpstan-phpunit": "^1.4",
53-
"phpstan/phpstan-symfony": "^1.4"
51+
"phpstan/phpstan": "^2.0",
52+
"phpstan/phpstan-phpunit": "^2.0",
53+
"phpstan/phpstan-symfony": "^2.0"
5454
},
5555
"scripts": {
5656
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",

phpstan-baseline.neon

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,115 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Parameter \\#1 \\$locationId of method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\LocationService\\:\\:loadLocation\\(\\) expects int, int\\|null given\\.$#"
4+
message: '#^Parameter \#1 \$locationId of method Ibexa\\Contracts\\Core\\Repository\\LocationService\:\:loadLocation\(\) expects int, int\|null given\.$#'
5+
identifier: argument.type
56
count: 1
67
path: src/bundle/Controller/QueryFieldRestController.php
78

89
-
9-
message: "#^Parameter \\#1 \\$uri of method Ibexa\\\\Contracts\\\\Rest\\\\UriParser\\\\UriParserInterface\\:\\:getAttributeFromUri\\(\\) expects string, string\\|null given\\.$#"
10+
message: '#^Parameter \#1 \$uri of method Ibexa\\Contracts\\Rest\\UriParser\\UriParserInterface\:\:getAttributeFromUri\(\) expects string, string\|null given\.$#'
11+
identifier: argument.type
1012
count: 1
1113
path: src/bundle/Controller/QueryFieldRestController.php
1214

1315
-
14-
message: "#^Argument of an invalid type array\\|bool\\|float\\|int\\|string\\|null supplied for foreach, only iterables are supported\\.$#"
16+
message: '#^Argument of an invalid type array\|bool\|float\|int\|string\|null supplied for foreach, only iterables are supported\.$#'
17+
identifier: foreach.nonIterable
1518
count: 1
1619
path: src/bundle/DependencyInjection/Compiler/FieldDefinitionIdentifierViewMatcherPass.php
1720

1821
-
19-
message: "#^Cannot access offset \\(int\\|string\\) on non\\-empty\\-array\\|bool\\|float\\|int\\|string\\|null\\.$#"
22+
message: '#^Cannot access offset \(int\|string\) on non\-empty\-array\|bool\|float\|int\|string\|null\.$#'
23+
identifier: offsetAccess.nonOffsetAccessible
2024
count: 1
2125
path: src/bundle/DependencyInjection/Compiler/FieldDefinitionIdentifierViewMatcherPass.php
2226

2327
-
24-
message: "#^Parameter \\#2 \\$callback of function array_filter expects \\(callable\\(int\\|string\\)\\: bool\\)\\|null, Closure\\(mixed\\)\\: \\(0\\|1\\|false\\) given\\.$#"
28+
message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(int\|string\)\: bool\)\|null, Closure\(mixed\)\: \(0\|1\|false\) given\.$#'
29+
identifier: argument.type
2530
count: 1
2631
path: src/bundle/DependencyInjection/Compiler/FieldDefinitionIdentifierViewMatcherPass.php
2732

2833
-
29-
message: "#^Parameter \\#1 \\$queryTypeIdentifier of method Ibexa\\\\Bundle\\\\FieldTypeQuery\\\\DependencyInjection\\\\Compiler\\\\QueryTypesListPass\\:\\:buildQueryTypeName\\(\\) expects string, int\\|string given\\.$#"
34+
message: '#^Parameter \#1 \$queryTypeIdentifier of method Ibexa\\Bundle\\FieldTypeQuery\\DependencyInjection\\Compiler\\QueryTypesListPass\:\:buildQueryTypeName\(\) expects string, int\|string given\.$#'
35+
identifier: argument.type
3036
count: 1
3137
path: src/bundle/DependencyInjection/Compiler/QueryTypesListPass.php
3238

3339
-
34-
message: "#^Parameter \\#1 \\$input of static method Symfony\\\\Component\\\\Yaml\\\\Yaml\\:\\:parse\\(\\) expects string, string\\|false given\\.$#"
40+
message: '#^Parameter \#1 \$input of static method Symfony\\Component\\Yaml\\Yaml\:\:parse\(\) expects string, string\|false given\.$#'
41+
identifier: argument.type
3542
count: 1
3643
path: src/bundle/DependencyInjection/IbexaFieldTypeQueryExtension.php
3744

3845
-
39-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\ContentView\\\\QueryResultsInjector\\:\\:__construct\\(\\) has parameter \\$views with no value type specified in iterable type array\\.$#"
46+
message: '#^Method Ibexa\\FieldTypeQuery\\ContentView\\QueryResultsInjector\:\:__construct\(\) has parameter \$views with no value type specified in iterable type array\.$#'
47+
identifier: missingType.iterableValue
4048
count: 1
4149
path: src/lib/ContentView/QueryResultsInjector.php
4250

4351
-
44-
message: "#^Property Ibexa\\\\FieldTypeQuery\\\\ContentView\\\\QueryResultsInjector\\:\\:\\$queryFieldService \\(Ibexa\\\\Contracts\\\\FieldTypeQuery\\\\QueryFieldLocationService&Ibexa\\\\Contracts\\\\FieldTypeQuery\\\\QueryFieldServiceInterface\\) does not accept Ibexa\\\\Contracts\\\\FieldTypeQuery\\\\QueryFieldServiceInterface\\.$#"
52+
message: '#^Property Ibexa\\FieldTypeQuery\\ContentView\\QueryResultsInjector\:\:\$queryFieldService \(Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldLocationService&Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\) does not accept Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\.$#'
53+
identifier: assign.propertyType
4554
count: 1
4655
path: src/lib/ContentView/QueryResultsInjector.php
4756

4857
-
49-
message: "#^Property Ibexa\\\\FieldTypeQuery\\\\ContentView\\\\QueryResultsInjector\\:\\:\\$views type has no value type specified in iterable type array\\.$#"
58+
message: '#^Property Ibexa\\FieldTypeQuery\\ContentView\\QueryResultsInjector\:\:\$views type has no value type specified in iterable type array\.$#'
59+
identifier: missingType.iterableValue
5060
count: 1
5161
path: src/lib/ContentView/QueryResultsInjector.php
5262

5363
-
54-
message: "#^Property Ibexa\\\\FieldTypeQuery\\\\ExceptionSafeQueryFieldService\\:\\:\\$inner \\(Ibexa\\\\Contracts\\\\FieldTypeQuery\\\\QueryFieldLocationService&Ibexa\\\\Contracts\\\\FieldTypeQuery\\\\QueryFieldServiceInterface\\) does not accept Ibexa\\\\Contracts\\\\FieldTypeQuery\\\\QueryFieldServiceInterface\\.$#"
64+
message: '#^Property Ibexa\\FieldTypeQuery\\ExceptionSafeQueryFieldService\:\:\$inner \(Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldLocationService&Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\) does not accept Ibexa\\Contracts\\FieldTypeQuery\\QueryFieldServiceInterface\.$#'
65+
identifier: assign.propertyType
5566
count: 1
5667
path: src/lib/ExceptionSafeQueryFieldService.php
5768

5869
-
59-
message: "#^Generator expects key type string, string\\|null given\\.$#"
70+
message: '#^Generator expects key type string, string\|null given\.$#'
71+
identifier: generator.keyType
6072
count: 1
6173
path: src/lib/FieldType/Mapper/QueryFormMapper.php
6274

6375
-
64-
message: "#^Property Ibexa\\\\Core\\\\Persistence\\\\Legacy\\\\Content\\\\StorageFieldValue\\:\\:\\$dataText \\(string\\) does not accept array\\|bool\\|float\\|int\\|string\\|null\\.$#"
76+
message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\StorageFieldValue\:\:\$dataText \(string\) does not accept array\|bool\|float\|int\|string\|null\.$#'
77+
identifier: assign.propertyType
6578
count: 1
6679
path: src/lib/Persistence/Legacy/Content/FieldValue/Converter/QueryConverter.php
6780

6881
-
69-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:isExpression\\(\\) has parameter \\$expression with no type specified\\.$#"
82+
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:isExpression\(\) has parameter \$expression with no type specified\.$#'
83+
identifier: missingType.parameter
7084
count: 1
7185
path: src/lib/QueryFieldService.php
7286

7387
-
74-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:prepareQuery\\(\\) has parameter \\$extraParameters with no value type specified in iterable type array\\.$#"
88+
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:prepareQuery\(\) has parameter \$extraParameters with no value type specified in iterable type array\.$#'
89+
identifier: missingType.iterableValue
7590
count: 1
7691
path: src/lib/QueryFieldService.php
7792

7893
-
79-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:resolveExpression\\(\\) has no return type specified\\.$#"
94+
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveExpression\(\) has parameter \$variables with no value type specified in iterable type array\.$#'
95+
identifier: missingType.iterableValue
8096
count: 1
8197
path: src/lib/QueryFieldService.php
8298

8399
-
84-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:resolveExpression\\(\\) has parameter \\$variables with no value type specified in iterable type array\\.$#"
100+
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveParameters\(\) has parameter \$expressions with no value type specified in iterable type array\.$#'
101+
identifier: missingType.iterableValue
85102
count: 1
86103
path: src/lib/QueryFieldService.php
87104

88105
-
89-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:resolveParameters\\(\\) has parameter \\$expressions with no value type specified in iterable type array\\.$#"
106+
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveParameters\(\) has parameter \$variables with no value type specified in iterable type array\.$#'
107+
identifier: missingType.iterableValue
90108
count: 1
91109
path: src/lib/QueryFieldService.php
92110

93111
-
94-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:resolveParameters\\(\\) has parameter \\$variables with no value type specified in iterable type array\\.$#"
95-
count: 1
96-
path: src/lib/QueryFieldService.php
97-
98-
-
99-
message: "#^Method Ibexa\\\\FieldTypeQuery\\\\QueryFieldService\\:\\:resolveParameters\\(\\) return type has no value type specified in iterable type array\\.$#"
112+
message: '#^Method Ibexa\\FieldTypeQuery\\QueryFieldService\:\:resolveParameters\(\) return type has no value type specified in iterable type array\.$#'
113+
identifier: missingType.iterableValue
100114
count: 1
101115
path: src/lib/QueryFieldService.php

spec/ContentView/FieldDefinitionIdentifierMatcherSpec.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FieldDefinitionIdentifierMatcherSpec extends ObjectBehavior
3030

3131
public const FIELD_DEFINITION_IDENTIFIER = 'field_definition';
3232

33-
public function it_is_initializable()
33+
public function it_is_initializable(): void
3434
{
3535
$this->shouldHaveType(FieldDefinitionIdentifierMatcher::class);
3636
$this->shouldHaveType(ViewMatcherInterface::class);
@@ -45,27 +45,27 @@ public static function initialize(Repository $repository, array $matchingConfig)
4545
return $matcher;
4646
}
4747

48-
public function let(Repository $repository, ContentTypeService $contentTypeService)
48+
public function let(Repository $repository, ContentTypeService $contentTypeService): void
4949
{
5050
$repository->getContentTypeService()->willReturn($contentTypeService);
5151
$contentTypeService->loadContentType(self::CONTENT_TYPE_ID_WITHOUT_FIELD_DEFINITION)->willReturn($this->createContentTypeWithoutFieldDefinition());
5252
$contentTypeService->loadContentType(self::CONTENT_TYPE_ID_WITH_FIELD_DEFINITION)->willReturn($this->createMatchingContentTypeWithFieldDefinition());
5353
$this->beConstructedThrough([$this, 'initialize'], [$repository, [self::FIELD_DEFINITION_IDENTIFIER]]);
5454
}
5555

56-
public function it_does_not_match_if_field_definition_identifier_does_not_exist()
56+
public function it_does_not_match_if_field_definition_identifier_does_not_exist(): void
5757
{
5858
$view = $this->buildView(self::CONTENT_TYPE_ID_WITHOUT_FIELD_DEFINITION);
5959
$this->match($view)->shouldBe(false);
6060
}
6161

62-
public function it_matches_if_field_definition_identifier_matches()
62+
public function it_matches_if_field_definition_identifier_matches(): void
6363
{
6464
$view = $this->buildView(self::CONTENT_TYPE_ID_WITH_FIELD_DEFINITION);
6565
$this->match($view)->shouldBe(true);
6666
}
6767

68-
private function buildView($contentTypeId): ContentView
68+
private function buildView(int $contentTypeId): ContentView
6969
{
7070
$view = new ContentView();
7171
$view->setContent(

spec/ContentView/QueryResultsInjectorSpec.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ class QueryResultsInjectorSpec extends ObjectBehavior
2828
public const VIEWS = ['field' => self::FIELD_VIEW, 'item' => self::ITEM_VIEW];
2929
public const FIELD_DEFINITION_IDENTIFIER = 'query_field';
3030

31-
/** @var \Ibexa\Core\MVC\Symfony\View\ContentView */
32-
private $view;
31+
private ContentView $view;
3332

34-
/** @var \Ibexa\Core\MVC\Symfony\View\Event\FilterViewParametersEvent */
35-
private $event;
33+
private FilterViewParametersEvent $event;
3634

3735
public function __construct()
3836
{
@@ -52,7 +50,7 @@ public function __construct()
5250
);
5351
}
5452

55-
public function it_is_initializable()
53+
public function it_is_initializable(): void
5654
{
5755
$this->shouldHaveType(QueryResultsInjector::class);
5856
}
@@ -61,7 +59,7 @@ public function let(
6159
QueryFieldServiceInterface $queryFieldService,
6260
FilterViewParametersEvent $event,
6361
RequestStack $requestStack
64-
) {
62+
): void {
6563
$this->beConstructedWith($queryFieldService, self::VIEWS, $requestStack);
6664
$event->getView()->willReturn($this->view);
6765
$event->getBuilderParameters()->willReturn(
@@ -76,37 +74,37 @@ public function let(
7674
public function it_throws_an_InvalidArgumentException_if_no_item_view_is_provided(
7775
QueryFieldServiceInterface $queryFieldService,
7876
RequestStack $requestStack
79-
) {
77+
): void {
8078
$this->beConstructedWith($queryFieldService, ['field' => self::FIELD_VIEW], $requestStack);
8179
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
8280
}
8381

8482
public function it_throws_an_InvalidArgumentException_if_no_field_view_is_provided(
8583
QueryFieldServiceInterface $queryFieldService,
8684
RequestStack $requestStack
87-
) {
85+
): void {
8886
$this->beConstructedWith($queryFieldService, ['item' => 'field'], $requestStack);
8987
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
9088
}
9189

92-
public function it_is_an_event_subscriber()
90+
public function it_is_an_event_subscriber(): void
9391
{
9492
$this->shouldHaveType(EventSubscriberInterface::class);
9593
}
9694

97-
public function it_subscribes_to_the_FILTER_VIEW_PARAMETERS_View_Event()
95+
public function it_subscribes_to_the_FILTER_VIEW_PARAMETERS_View_Event(): void
9896
{
9997
$this->getSubscribedEvents()->shouldSubscribeTo(ViewEvents::FILTER_VIEW_PARAMETERS);
10098
}
10199

102-
public function it_does_nothing_for_non_field_views(QueryFieldServiceInterface $queryFieldService)
100+
public function it_does_nothing_for_non_field_views(QueryFieldServiceInterface $queryFieldService): void
103101
{
104102
$this->event->getView()->setViewType(self::OTHER_VIEW);
105103
$this->injectQueryResults($this->event);
106104
$queryFieldService->getPaginationConfiguration(Argument::any())->shouldNotHaveBeenCalled();
107105
}
108106

109-
public function it_adds_the_query_results_for_the_field_view_without_pagination(QueryFieldServiceInterface $queryFieldService)
107+
public function it_adds_the_query_results_for_the_field_view_without_pagination(QueryFieldServiceInterface $queryFieldService): void
110108
{
111109
$content = $this->createContentItem();
112110

@@ -133,7 +131,7 @@ public function it_adds_the_query_results_for_the_field_view_without_pagination(
133131
public function it_adds_the_query_results_for_the_field_view_with_pagination(
134132
FilterViewParametersEvent $event,
135133
QueryFieldServiceInterface $queryFieldService
136-
) {
134+
): void {
137135
$content = $this->createContentItem();
138136

139137
$queryFieldService
@@ -161,7 +159,7 @@ public function it_adds_the_query_results_for_the_field_view_with_pagination(
161159
public function getMatchers(): array
162160
{
163161
return [
164-
'subscribeTo' => static function ($return, $event) {
162+
'subscribeTo' => static function ($return, $event): bool {
165163
return is_array($return) && isset($return[$event]);
166164
},
167165
];

spec/ExceptionSafeQueryFieldServiceSpec.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class ExceptionSafeQueryFieldServiceSpec extends ObjectBehavior
1717
{
18-
public function let(QueryFieldServiceInterface $queryFieldService)
18+
public function let(QueryFieldServiceInterface $queryFieldService): void
1919
{
2020
$arguments = [
2121
Argument::type(Content::class),
@@ -31,24 +31,24 @@ public function let(QueryFieldServiceInterface $queryFieldService)
3131
$this->beConstructedWith($queryFieldService);
3232
}
3333

34-
public function it_is_initializable()
34+
public function it_is_initializable(): void
3535
{
3636
$this->shouldHaveType(ExceptionSafeQueryFieldService::class);
3737
}
3838

39-
public function it_should_return_empty_results_on_count_content_items()
39+
public function it_should_return_empty_results_on_count_content_items(): void
4040
{
4141
$result = $this->countContentItems(new Content([]), 'any');
4242
$result->shouldBe(0);
4343
}
4444

45-
public function it_should_return_empty_results_on_load_content_items()
45+
public function it_should_return_empty_results_on_load_content_items(): void
4646
{
4747
$result = $this->loadContentItems(new Content([]), 'any');
4848
$result->shouldBe([]);
4949
}
5050

51-
public function it_should_return_empty_results_on_load_content_items_slice()
51+
public function it_should_return_empty_results_on_load_content_items_slice(): void
5252
{
5353
$result = $this->loadContentItemsSlice(new Content([]), 'any', 0, 5);
5454
$result->shouldBe([]);

0 commit comments

Comments
 (0)