Skip to content

Commit

Permalink
[CI] Added phpstan with baseline & fixed some issues (#55)
Browse files Browse the repository at this point in the history
* [CI] Added phpstan with baseline & fixed some issues

* cs fixes

* bumped phpstan to 2.0
  • Loading branch information
ViniTou authored Dec 13, 2024
1 parent 31788dc commit d53e1c2
Show file tree
Hide file tree
Showing 21 changed files with 271 additions and 156 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ jobs:
- name: Run test suite
run: composer run-script --timeout=600 test

- name: Run PHPStan analysis
run: composer run-script phpstan

integration-tests:
name: Tests
needs: tests
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"php": "^7.4 || ^8.0",
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-json": "*",
"ibexa/core": "~4.6.0@dev",
"ibexa/content-forms": "~4.6.0@dev",
"ibexa/graphql": "~4.6.0@dev",
Expand All @@ -48,13 +49,17 @@
"ibexa/design-engine": "~4.6.0@dev",
"ibexa/code-style": "^1.0",
"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9.5"
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-symfony": "^2.0"
},
"scripts": {
"fix-cs": "php-cs-fixer fix --config=.php-cs-fixer.php -v --show-progress=dots",
"check-cs": "@fix-cs --dry-run",
"test": "phpunit -c phpunit.xml",
"test-integration": "phpunit -c phpunit.integration.xml"
"test-integration": "phpunit -c phpunit.integration.xml",
"phpstan": "phpstan analyse"
},
"extra": {
"branch-alias": {
Expand Down
211 changes: 211 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
parameters:
ignoreErrors:
-
message: '#^Cannot access offset ''entries'' on array\|bool\|float\|int\|string\|null\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Cannot call method fetchAll\(\) on Doctrine\\DBAL\\ForwardCompatibility\\Result\|int\|string\.$#'
identifier: method.nonObject
count: 2
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Cannot call method fetchColumn\(\) on Doctrine\\DBAL\\ForwardCompatibility\\Result\|int\|string\.$#'
identifier: method.nonObject
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:configure\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) has parameter \$cells with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) has parameter \$columns with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:convertCellsToRows\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:getContentClassAttributes\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Method Ibexa\\Bundle\\FieldTypeMatrix\\Command\\MigrateLegacyMatrixCommand\:\:getContentObjectAttributes\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Variable \$xml might not be defined\.$#'
identifier: variable.undefined
count: 1
path: src/bundle/Command/MigrateLegacyMatrixCommand.php

-
message: '#^Parameter \#1 \$input of static method Symfony\\Component\\Yaml\\Yaml\:\:parse\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 1
path: src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php

-
message: '#^Property Ibexa\\Core\\Persistence\\Legacy\\Content\\StorageFieldDefinition\:\:\$dataText5 \(string\) on left side of \?\? is not nullable\.$#'
identifier: nullCoalesce.property
count: 1
path: src/lib/FieldType/Converter/MatrixConverter.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__construct\(\) has parameter \$cells with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__get\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__get\(\) has parameter \$name with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:__isset\(\) has parameter \$name with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:getCells\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(string\)\: bool\)\|null, ''strlen'' given\.$#'
identifier: argument.type
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Property Ibexa\\FieldTypeMatrix\\FieldType\\Value\\Row\:\:\$cells type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/FieldType/Value/Row.php

-
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\ColumnType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/lib/Form/Type/ColumnType.php

-
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\FieldType\\MatrixCollectionType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/lib/Form/Type/FieldType/MatrixCollectionType.php

-
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\FieldType\\MatrixEntryType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/lib/Form/Type/FieldType/MatrixEntryType.php

-
message: '#^Class Ibexa\\FieldTypeMatrix\\Form\\Type\\FieldType\\MatrixFieldType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/lib/Form/Type/FieldType/MatrixFieldType.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\InputHandler\:\:toFieldValue\(\) has parameter \$input with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/GraphQL/InputHandler.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\InputHandler\:\:toFieldValue\(\) has parameter \$inputFormat with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/GraphQL/InputHandler.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:canWork\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:typeName\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionInputSchemaWorker\:\:work\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:canWork\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:typeName\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\Schema\\MatrixFieldDefinitionSchemaWorker\:\:work\(\) has parameter \$args with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\SilentRow\:\:__get\(\) has no return type specified\.$#'
identifier: missingType.return
count: 1
path: src/lib/GraphQL/SilentRow.php

-
message: '#^Method Ibexa\\FieldTypeMatrix\\GraphQL\\SilentRow\:\:__get\(\) has parameter \$name with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/lib/GraphQL/SilentRow.php

-
message: '#^Static property Ibexa\\Contracts\\Core\\Test\\Repository\\SetupFactory\\Legacy\:\:\$serviceContainer \(Ibexa\\Core\\Base\\ServiceContainer\) in isset\(\) is not nullable\.$#'
identifier: isset.property
count: 1
path: tests/lib/LegacySetupFactory.php

-
message: '#^Access to an undefined property Ibexa\\Contracts\\Core\\Repository\\Values\\ValueObject\:\:\$id\.$#'
identifier: property.notFound
count: 1
path: tests/lib/Repository/SearchServiceTest.php
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon

parameters:
level: 8
paths:
- src
- tests
25 changes: 4 additions & 21 deletions src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@

class IbexaFieldTypeMatrixExtension extends Extension implements PrependExtensionInterface
{
/**
* Loads a specific configuration.
*
* @param array $configs
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader(
$container,
Expand All @@ -35,32 +29,21 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.yaml');
}

/**
* Allow an extension to prepend the extension configurations.
*
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
$this->prependKernelSettings($container);
$this->prependJMSTranslation($container);
$this->prependGraphQL($container);
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prependKernelSettings(ContainerBuilder $container)
public function prependKernelSettings(ContainerBuilder $container): void
{
$configFile = __DIR__ . '/../Resources/config/kernel.yaml';
$config = Yaml::parse(file_get_contents($configFile));
$container->prependExtensionConfig('ibexa', $config);
$container->addResource(new FileResource($configFile));
}

/**
* @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
*/
public function prependJMSTranslation(ContainerBuilder $container): void
{
$container->prependExtensionConfig('jms_translation', [
Expand All @@ -78,7 +61,7 @@ public function prependJMSTranslation(ContainerBuilder $container): void
]);
}

private function prependGraphQL(ContainerBuilder $container)
private function prependGraphQL(ContainerBuilder $container): void
{
$container->prependExtensionConfig('overblog_graphql', [
'definitions' => [
Expand Down
4 changes: 2 additions & 2 deletions src/lib/FieldType/Converter/MatrixConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function toStorageValue(FieldValue $value, StorageFieldValue $storageFiel
{
$entries = $value->data['entries'] ?? [];

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

/**
Expand Down Expand Up @@ -67,7 +67,7 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField
});

$storageDef->dataInt1 = $minimumRows;
$storageDef->dataText5 = json_encode($columns);
$storageDef->dataText5 = json_encode($columns) ?: '';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/lib/FieldType/Mapper/MatrixFormMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MatrixFormMapper implements FieldDefinitionFormMapperInterface, FieldValue
* - field settings
* - default value.
*
* @param \Symfony\Component\Form\FormInterface $fieldDefinitionForm form for current FieldDefinition
* @param \Symfony\Component\Form\FormInterface<\Ibexa\AdminUi\Form\Data\FieldDefinitionData> $fieldDefinitionForm form for current FieldDefinition
* @param \Ibexa\AdminUi\Form\Data\FieldDefinitionData $data underlying data for current FieldDefinition form
*/
public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, FieldDefinitionData $data): void
Expand Down Expand Up @@ -61,7 +61,7 @@ public function mapFieldDefinitionForm(FormInterface $fieldDefinitionForm, Field
* Maps Field form to current FieldType.
* Allows to add form fields for content edition.
*
* @param \Symfony\Component\Form\FormInterface $fieldForm form for the current Field
* @param \Symfony\Component\Form\FormInterface<\Ibexa\Contracts\ContentForms\Data\Content\FieldData> $fieldForm form for the current Field
* @param \Ibexa\Contracts\ContentForms\Data\Content\FieldData $data underlying data for current Field form
*/
public function mapFieldValueForm(FormInterface $fieldForm, FieldData $data): void
Expand Down
9 changes: 4 additions & 5 deletions src/lib/FieldType/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin
*/
public function getEmptyValue(): SPIValue
{
$value = new Value([]);

return $value;
return new Value([]);
}

/**
Expand All @@ -147,7 +145,7 @@ public function fromHash($hash): SPIValue
/**
* {@inheritdoc}
*/
protected function checkValueStructure(FieldTypeValue $value)
protected function checkValueStructure(FieldTypeValue $value): void
{
// Value is self-contained and strong typed
return;
Expand All @@ -164,6 +162,8 @@ public function isEmptyValue(SPIValue $value): bool

/**
* {@inheritdoc}
*
* @param \Ibexa\FieldTypeMatrix\FieldType\Value $value
*/
public function validate(FieldDefinition $fieldDefinition, SPIValue $value)
{
Expand All @@ -173,7 +173,6 @@ public function validate(FieldDefinition $fieldDefinition, SPIValue $value)

$countNonEmptyRows = 0;

/** @var \Ibexa\FieldTypeMatrix\FieldType\Value $value */
foreach ($value->getRows() as $row) {
if (!$row->isEmpty()) {
++$countNonEmptyRows;
Expand Down
Loading

0 comments on commit d53e1c2

Please sign in to comment.