Skip to content

Commit d53e1c2

Browse files
authored
[CI] Added phpstan with baseline & fixed some issues (#55)
* [CI] Added phpstan with baseline & fixed some issues * cs fixes * bumped phpstan to 2.0
1 parent 31788dc commit d53e1c2

21 files changed

+271
-156
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ jobs:
6767
- name: Run test suite
6868
run: composer run-script --timeout=600 test
6969

70+
- name: Run PHPStan analysis
71+
run: composer run-script phpstan
72+
7073
integration-tests:
7174
name: Tests
7275
needs: tests

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"php": "^7.4 || ^8.0",
2525
"ext-libxml": "*",
2626
"ext-simplexml": "*",
27+
"ext-json": "*",
2728
"ibexa/core": "~4.6.0@dev",
2829
"ibexa/content-forms": "~4.6.0@dev",
2930
"ibexa/graphql": "~4.6.0@dev",
@@ -48,13 +49,17 @@
4849
"ibexa/design-engine": "~4.6.0@dev",
4950
"ibexa/code-style": "^1.0",
5051
"friendsofphp/php-cs-fixer": "^3.0",
51-
"phpunit/phpunit": "^9.5"
52+
"phpunit/phpunit": "^9.5",
53+
"phpstan/phpstan": "^2.0",
54+
"phpstan/phpstan-phpunit": "^2.0",
55+
"phpstan/phpstan-symfony": "^2.0"
5256
},
5357
"scripts": {
5458
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
5559
"check-cs": "@fix-cs --dry-run",
5660
"test": "phpunit -c phpunit.xml",
57-
"test-integration": "phpunit -c phpunit.integration.xml"
61+
"test-integration": "phpunit -c phpunit.integration.xml",
62+
"phpstan": "phpstan analyse"
5863
},
5964
"extra": {
6065
"branch-alias": {

phpstan-baseline.neon

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Cannot access offset ''entries'' on array\|bool\|float\|int\|string\|null\.$#'
5+
identifier: offsetAccess.nonOffsetAccessible
6+
count: 1
7+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
8+
9+
-
10+
message: '#^Cannot call method fetchAll\(\) on Doctrine\\DBAL\\ForwardCompatibility\\Result\|int\|string\.$#'
11+
identifier: method.nonObject
12+
count: 2
13+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
14+
15+
-
16+
message: '#^Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\ForwardCompatibility\\Result\|int\|string\.$#'
17+
identifier: method.nonObject
18+
count: 1
19+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
20+
21+
-
22+
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:configure\(\) has no return type specified\.$#'
23+
identifier: missingType.return
24+
count: 1
25+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
26+
27+
-
28+
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) has parameter \$cells with no value type specified in iterable type array\.$#'
29+
identifier: missingType.iterableValue
30+
count: 1
31+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
32+
33+
-
34+
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) has parameter \$columns with no value type specified in iterable type array\.$#'
35+
identifier: missingType.iterableValue
36+
count: 1
37+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
38+
39+
-
40+
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) return type has no value type specified in iterable type array\.$#'
41+
identifier: missingType.iterableValue
42+
count: 1
43+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
44+
45+
-
46+
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:getContentClassAttributes\(\) return type has no value type specified in iterable type array\.$#'
47+
identifier: missingType.iterableValue
48+
count: 1
49+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
50+
51+
-
52+
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:getContentObjectAttributes\(\) return type has no value type specified in iterable type array\.$#'
53+
identifier: missingType.iterableValue
54+
count: 1
55+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
56+
57+
-
58+
message: '#^Variable \$xml might not be defined\.$#'
59+
identifier: variable.undefined
60+
count: 1
61+
path: src/bundle/Command/MigrateLegacyMatrixCommand.php
62+
63+
-
64+
message: '#^Parameter \#1 \$input of static method Symfony\\Component\\Yaml\\Yaml\:\:parse\(\) expects string, string\|false given\.$#'
65+
identifier: argument.type
66+
count: 1
67+
path: src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php
68+
69+
-
70+
message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\StorageFieldDefinition\:\:\$dataText5 \(string\) on left side of \?\? is not nullable\.$#'
71+
identifier: nullCoalesce.property
72+
count: 1
73+
path: src/lib/FieldType/Converter/MatrixConverter.php
74+
75+
-
76+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__construct\(\) has parameter \$cells with no value type specified in iterable type array\.$#'
77+
identifier: missingType.iterableValue
78+
count: 1
79+
path: src/lib/FieldType/Value/Row.php
80+
81+
-
82+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__get\(\) has no return type specified\.$#'
83+
identifier: missingType.return
84+
count: 1
85+
path: src/lib/FieldType/Value/Row.php
86+
87+
-
88+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__get\(\) has parameter \$name with no type specified\.$#'
89+
identifier: missingType.parameter
90+
count: 1
91+
path: src/lib/FieldType/Value/Row.php
92+
93+
-
94+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__isset\(\) has parameter \$name with no type specified\.$#'
95+
identifier: missingType.parameter
96+
count: 1
97+
path: src/lib/FieldType/Value/Row.php
98+
99+
-
100+
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:getCells\(\) return type has no value type specified in iterable type array\.$#'
101+
identifier: missingType.iterableValue
102+
count: 1
103+
path: src/lib/FieldType/Value/Row.php
104+
105+
-
106+
message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(string\)\: bool\)\|null, ''strlen'' given\.$#'
107+
identifier: argument.type
108+
count: 1
109+
path: src/lib/FieldType/Value/Row.php
110+
111+
-
112+
message: '#^Property Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:\$cells type has no value type specified in iterable type array\.$#'
113+
identifier: missingType.iterableValue
114+
count: 1
115+
path: src/lib/FieldType/Value/Row.php
116+
117+
-
118+
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\ColumnType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
119+
identifier: missingType.generics
120+
count: 1
121+
path: src/lib/Form/Type/ColumnType.php
122+
123+
-
124+
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\FieldType\\MatrixCollectionType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
125+
identifier: missingType.generics
126+
count: 1
127+
path: src/lib/Form/Type/FieldType/MatrixCollectionType.php
128+
129+
-
130+
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\FieldType\\MatrixEntryType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
131+
identifier: missingType.generics
132+
count: 1
133+
path: src/lib/Form/Type/FieldType/MatrixEntryType.php
134+
135+
-
136+
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\FieldType\\MatrixFieldType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
137+
identifier: missingType.generics
138+
count: 1
139+
path: src/lib/Form/Type/FieldType/MatrixFieldType.php
140+
141+
-
142+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\InputHandler\:\:toFieldValue\(\) has parameter \$input with no type specified\.$#'
143+
identifier: missingType.parameter
144+
count: 1
145+
path: src/lib/GraphQL/InputHandler.php
146+
147+
-
148+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\InputHandler\:\:toFieldValue\(\) has parameter \$inputFormat with no type specified\.$#'
149+
identifier: missingType.parameter
150+
count: 1
151+
path: src/lib/GraphQL/InputHandler.php
152+
153+
-
154+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:canWork\(\) has parameter \$args with no value type specified in iterable type array\.$#'
155+
identifier: missingType.iterableValue
156+
count: 1
157+
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php
158+
159+
-
160+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:typeName\(\) has parameter \$args with no value type specified in iterable type array\.$#'
161+
identifier: missingType.iterableValue
162+
count: 1
163+
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php
164+
165+
-
166+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:work\(\) has parameter \$args with no value type specified in iterable type array\.$#'
167+
identifier: missingType.iterableValue
168+
count: 1
169+
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php
170+
171+
-
172+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:canWork\(\) has parameter \$args with no value type specified in iterable type array\.$#'
173+
identifier: missingType.iterableValue
174+
count: 1
175+
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php
176+
177+
-
178+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:typeName\(\) has parameter \$args with no value type specified in iterable type array\.$#'
179+
identifier: missingType.iterableValue
180+
count: 1
181+
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php
182+
183+
-
184+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:work\(\) has parameter \$args with no value type specified in iterable type array\.$#'
185+
identifier: missingType.iterableValue
186+
count: 1
187+
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php
188+
189+
-
190+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\SilentRow\:\:__get\(\) has no return type specified\.$#'
191+
identifier: missingType.return
192+
count: 1
193+
path: src/lib/GraphQL/SilentRow.php
194+
195+
-
196+
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\SilentRow\:\:__get\(\) has parameter \$name with no type specified\.$#'
197+
identifier: missingType.parameter
198+
count: 1
199+
path: src/lib/GraphQL/SilentRow.php
200+
201+
-
202+
message: '#^Static property Ibexa\\Contracts\\Core\\Test\\Repository\\SetupFactory\\Legacy\:\:\$serviceContainer \(Ibexa\\Core\\Base\\ServiceContainer\) in isset\(\) is not nullable\.$#'
203+
identifier: isset.property
204+
count: 1
205+
path: tests/lib/LegacySetupFactory.php
206+
207+
-
208+
message: '#^Access to an undefined property Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\:\:\$id\.$#'
209+
identifier: property.notFound
210+
count: 1
211+
path: tests/lib/Repository/SearchServiceTest.php

phpstan.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- vendor/phpstan/phpstan-phpunit/extension.neon
4+
- vendor/phpstan/phpstan-symfony/extension.neon
5+
6+
parameters:
7+
level: 8
8+
paths:
9+
- src
10+
- tests

src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,7 @@
1818

1919
class IbexaFieldTypeMatrixExtension extends Extension implements PrependExtensionInterface
2020
{
21-
/**
22-
* Loads a specific configuration.
23-
*
24-
* @param array $configs
25-
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
26-
*/
27-
public function load(array $configs, ContainerBuilder $container)
21+
public function load(array $configs, ContainerBuilder $container): void
2822
{
2923
$loader = new YamlFileLoader(
3024
$container,
@@ -35,32 +29,21 @@ public function load(array $configs, ContainerBuilder $container)
3529
$loader->load('services.yaml');
3630
}
3731

38-
/**
39-
* Allow an extension to prepend the extension configurations.
40-
*
41-
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
42-
*/
43-
public function prepend(ContainerBuilder $container)
32+
public function prepend(ContainerBuilder $container): void
4433
{
4534
$this->prependKernelSettings($container);
4635
$this->prependJMSTranslation($container);
4736
$this->prependGraphQL($container);
4837
}
4938

50-
/**
51-
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
52-
*/
53-
public function prependKernelSettings(ContainerBuilder $container)
39+
public function prependKernelSettings(ContainerBuilder $container): void
5440
{
5541
$configFile = __DIR__ . '/../Resources/config/kernel.yaml';
5642
$config = Yaml::parse(file_get_contents($configFile));
5743
$container->prependExtensionConfig('ibexa', $config);
5844
$container->addResource(new FileResource($configFile));
5945
}
6046

61-
/**
62-
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
63-
*/
6447
public function prependJMSTranslation(ContainerBuilder $container): void
6548
{
6649
$container->prependExtensionConfig('jms_translation', [
@@ -78,7 +61,7 @@ public function prependJMSTranslation(ContainerBuilder $container): void
7861
]);
7962
}
8063

81-
private function prependGraphQL(ContainerBuilder $container)
64+
private function prependGraphQL(ContainerBuilder $container): void
8265
{
8366
$container->prependExtensionConfig('overblog_graphql', [
8467
'definitions' => [

src/lib/FieldType/Converter/MatrixConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
3030
{
3131
$entries = $value->data['entries'] ?? [];
3232

33-
$storageFieldValue->dataText = json_encode(array_values($entries));
33+
$storageFieldValue->dataText = json_encode(array_values($entries)) ?: '';
3434
}
3535

3636
/**
@@ -67,7 +67,7 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField
6767
});
6868

6969
$storageDef->dataInt1 = $minimumRows;
70-
$storageDef->dataText5 = json_encode($columns);
70+
$storageDef->dataText5 = json_encode($columns) ?: '';
7171
}
7272

7373
/**

src/lib/FieldType/Mapper/MatrixFormMapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MatrixFormMapper implements FieldDefinitionFormMapperInterface, FieldValue
2727
* - field settings
2828
* - default value.
2929
*
30-
* @param \Symfony\Component\Form\FormInterface $fieldDefinitionForm form for current FieldDefinition
30+
* @param \Symfony\Component\Form\FormInterface<\Ibexa\AdminUi\Form\Data\FieldDefinitionData> $fieldDefinitionForm form for current FieldDefinition
3131
* @param \Ibexa\AdminUi\Form\Data\FieldDefinitionData $data underlying data for current FieldDefinition form
3232
*/
3333
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void
@@ -61,7 +61,7 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field
6161
* Maps Field form to current FieldType.
6262
* Allows to add form fields for content edition.
6363
*
64-
* @param \Symfony\Component\Form\FormInterface $fieldForm form for the current Field
64+
* @param \Symfony\Component\Form\FormInterface<\Ibexa\Contracts\ContentForms\Data\Content\FieldData> $fieldForm form for the current Field
6565
* @param \Ibexa\Contracts\ContentForms\Data\Content\FieldData $data underlying data for current Field form
6666
*/
6767
public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void

src/lib/FieldType/Type.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin
125125
*/
126126
public function getEmptyValue(): SPIValue
127127
{
128-
$value = new Value([]);
129-
130-
return $value;
128+
return new Value([]);
131129
}
132130

133131
/**
@@ -147,7 +145,7 @@ public function fromHash($hash): SPIValue
147145
/**
148146
* {@inheritdoc}
149147
*/
150-
protected function checkValueStructure(FieldTypeValue $value)
148+
protected function checkValueStructure(FieldTypeValue $value): void
151149
{
152150
// Value is self-contained and strong typed
153151
return;
@@ -164,6 +162,8 @@ public function isEmptyValue(SPIValue $value): bool
164162

165163
/**
166164
* {@inheritdoc}
165+
*
166+
* @param \Ibexa\FieldTypeMatrix\FieldType\Value $value
167167
*/
168168
public function validate(FieldDefinition $fieldDefinition, SPIValue $value)
169169
{
@@ -173,7 +173,6 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value)
173173

174174
$countNonEmptyRows = 0;
175175

176-
/** @var \Ibexa\FieldTypeMatrix\FieldType\Value $value */
177176
foreach ($value->getRows() as $row) {
178177
if (!$row->isEmpty()) {
179178
++$countNonEmptyRows;

0 commit comments

Comments
 (0)