From d53e1c29b18d4ff30dabcc6301286068e59fcc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Fri, 13 Dec 2024 14:57:13 +0100 Subject: [PATCH] [CI] Added phpstan with baseline & fixed some issues (#55) * [CI] Added phpstan with baseline & fixed some issues * cs fixes * bumped phpstan to 2.0 --- .github/workflows/ci.yaml | 3 + composer.json | 9 +- phpstan-baseline.neon | 211 ++++++++++++++++++ phpstan.neon | 10 + .../IbexaFieldTypeMatrixExtension.php | 25 +-- .../FieldType/Converter/MatrixConverter.php | 4 +- src/lib/FieldType/Mapper/MatrixFormMapper.php | 4 +- src/lib/FieldType/Type.php | 9 +- src/lib/FieldType/Value.php | 16 +- src/lib/FieldType/Value/Row.php | 23 +- src/lib/FieldType/Value/RowsCollection.php | 3 + .../Transformer/FieldTypeModelTransformer.php | 26 +-- src/lib/Form/Type/ColumnType.php | 7 - .../Type/FieldType/MatrixCollectionType.php | 17 -- .../Form/Type/FieldType/MatrixEntryType.php | 18 -- .../Form/Type/FieldType/MatrixFieldType.php | 9 - src/lib/GraphQL/FieldValueResolver.php | 9 +- ...MatrixFieldDefinitionInputSchemaWorker.php | 6 +- .../Schema/MatrixFieldDefinitionMapper.php | 8 +- .../MatrixFieldDefinitionSchemaWorker.php | 6 +- src/lib/GraphQL/Schema/NameHelper.php | 4 +- 21 files changed, 271 insertions(+), 156 deletions(-) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index aace7b2..0627b5f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/composer.json b/composer.json index c14a08c..13df9ca 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..5a65ec6 --- /dev/null +++ b/phpstan-baseline.neon @@ -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 diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..129755d --- /dev/null +++ b/phpstan.neon @@ -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 diff --git a/src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php b/src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php index da681aa..725eb53 100644 --- a/src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php +++ b/src/bundle/DependencyInjection/IbexaFieldTypeMatrixExtension.php @@ -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, @@ -35,22 +29,14 @@ 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)); @@ -58,9 +44,6 @@ public function prependKernelSettings(ContainerBuilder $container) $container->addResource(new FileResource($configFile)); } - /** - * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container - */ public function prependJMSTranslation(ContainerBuilder $container): void { $container->prependExtensionConfig('jms_translation', [ @@ -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' => [ diff --git a/src/lib/FieldType/Converter/MatrixConverter.php b/src/lib/FieldType/Converter/MatrixConverter.php index 394380d..5b8d94f 100644 --- a/src/lib/FieldType/Converter/MatrixConverter.php +++ b/src/lib/FieldType/Converter/MatrixConverter.php @@ -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)) ?: ''; } /** @@ -67,7 +67,7 @@ public function toStorageFieldDefinition(FieldDefinition $fieldDef, StorageField }); $storageDef->dataInt1 = $minimumRows; - $storageDef->dataText5 = json_encode($columns); + $storageDef->dataText5 = json_encode($columns) ?: ''; } /** diff --git a/src/lib/FieldType/Mapper/MatrixFormMapper.php b/src/lib/FieldType/Mapper/MatrixFormMapper.php index f3335dd..c7ddfae 100644 --- a/src/lib/FieldType/Mapper/MatrixFormMapper.php +++ b/src/lib/FieldType/Mapper/MatrixFormMapper.php @@ -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 @@ -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 diff --git a/src/lib/FieldType/Type.php b/src/lib/FieldType/Type.php index f6be935..8e5864e 100644 --- a/src/lib/FieldType/Type.php +++ b/src/lib/FieldType/Type.php @@ -125,9 +125,7 @@ public function getName(SPIValue $value, FieldDefinition $fieldDefinition, strin */ public function getEmptyValue(): SPIValue { - $value = new Value([]); - - return $value; + return new Value([]); } /** @@ -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; @@ -164,6 +162,8 @@ public function isEmptyValue(SPIValue $value): bool /** * {@inheritdoc} + * + * @param \Ibexa\FieldTypeMatrix\FieldType\Value $value */ public function validate(FieldDefinition $fieldDefinition, SPIValue $value) { @@ -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; diff --git a/src/lib/FieldType/Value.php b/src/lib/FieldType/Value.php index 02f0c3d..2baa4ee 100644 --- a/src/lib/FieldType/Value.php +++ b/src/lib/FieldType/Value.php @@ -13,38 +13,26 @@ class Value extends BaseValue { - /** @var \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection */ - protected $rows; + protected RowsCollection $rows; /** - * @param array $rows + * @param \Ibexa\FieldTypeMatrix\FieldType\Value\Row[] $rows */ public function __construct(array $rows = []) { $this->rows = new RowsCollection($rows); } - /** - * @return \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection - */ public function getRows(): RowsCollection { return $this->rows; } - /** - * @param \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection $rows - */ public function setRows(RowsCollection $rows): void { $this->rows = $rows; } - /** - * Returns a string representation of the field value. - * - * @return string - */ public function __toString(): string { return ''; diff --git a/src/lib/FieldType/Value/Row.php b/src/lib/FieldType/Value/Row.php index f111563..50d1f1c 100644 --- a/src/lib/FieldType/Value/Row.php +++ b/src/lib/FieldType/Value/Row.php @@ -10,29 +10,18 @@ class Row { - protected $cells; + protected array $cells; - /** - * Row constructor. - * - * @param array $cells - */ public function __construct(array $cells = []) { $this->cells = $cells; } - /** - * @return array - */ public function getCells(): array { return $this->cells; } - /** - * @return bool - */ public function isEmpty(): bool { $trimmed = array_map('trim', $this->cells); @@ -41,21 +30,11 @@ public function isEmpty(): bool return count($filtered) === 0; } - /** - * @param $name - * - * @return mixed - */ public function __get($name) { return $this->cells[$name]; } - /** - * @param $name - * - * @return bool - */ public function __isset($name): bool { return isset($this->cells[$name]); diff --git a/src/lib/FieldType/Value/RowsCollection.php b/src/lib/FieldType/Value/RowsCollection.php index 0322560..34d9a8e 100644 --- a/src/lib/FieldType/Value/RowsCollection.php +++ b/src/lib/FieldType/Value/RowsCollection.php @@ -11,6 +11,9 @@ use ArrayObject; use Ibexa\Core\Base\Exceptions\InvalidArgumentType; +/** + * @extends ArrayObject + */ class RowsCollection extends ArrayObject { /** diff --git a/src/lib/Form/Transformer/FieldTypeModelTransformer.php b/src/lib/Form/Transformer/FieldTypeModelTransformer.php index aa94e65..8714102 100644 --- a/src/lib/Form/Transformer/FieldTypeModelTransformer.php +++ b/src/lib/Form/Transformer/FieldTypeModelTransformer.php @@ -12,21 +12,19 @@ use Ibexa\FieldTypeMatrix\FieldType\Value\Row; use Symfony\Component\Form\DataTransformerInterface; +/** + * @implements DataTransformerInterface<\Ibexa\FieldTypeMatrix\FieldType\Value, array> + */ class FieldTypeModelTransformer implements DataTransformerInterface { - /** - * Transforms a value from the original representation to a transformed representation. - * - * @param mixed $value The value in the original representation - * - * @return mixed The value in the transformed representation - * - * @throws \Symfony\Component\Form\Exception\TransformationFailedException when the transformation fails - */ public function transform($value) { $hash['entries'] = []; + if ($value === null) { + return $hash; + } + foreach ($value->getRows() as $row) { $hash['entries'][] = $row->getCells(); } @@ -34,16 +32,6 @@ public function transform($value) return $hash; } - /** - * Transforms a value from the transformed representation to its original - * representation. - * - * @param mixed $value The value in the transformed representation - * - * @return mixed The value in the original representation - * - * @throws \Symfony\Component\Form\Exception\TransformationFailedException when the transformation fails - */ public function reverseTransform($value) { $entries = $value['entries'] ?? []; diff --git a/src/lib/Form/Type/ColumnType.php b/src/lib/Form/Type/ColumnType.php index 06118ae..22a831e 100644 --- a/src/lib/Form/Type/ColumnType.php +++ b/src/lib/Form/Type/ColumnType.php @@ -15,10 +15,6 @@ class ColumnType extends AbstractType { - /** - * @param \Symfony\Component\Form\FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder @@ -30,9 +26,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]); } - /** - * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefault('translation_domain', 'ibexa_matrix_fieldtype'); diff --git a/src/lib/Form/Type/FieldType/MatrixCollectionType.php b/src/lib/Form/Type/FieldType/MatrixCollectionType.php index 78ee3ee..709c596 100644 --- a/src/lib/Form/Type/FieldType/MatrixCollectionType.php +++ b/src/lib/Form/Type/FieldType/MatrixCollectionType.php @@ -16,25 +16,16 @@ class MatrixCollectionType extends AbstractType { - /** - * @return string - */ public function getName(): string { return $this->getBlockPrefix(); } - /** - * @return string - */ public function getBlockPrefix(): string { return 'ezplatform_fieldtype_ezmatrix_collection'; } - /** - * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefined(['columns', 'minimum_rows']); @@ -53,20 +44,12 @@ public function configureOptions(OptionsResolver $resolver): void parent::configureOptions($resolver); } - /** - * @param \Symfony\Component\Form\FormView $view - * @param \Symfony\Component\Form\FormInterface $form - * @param array $options - */ public function buildView(FormView $view, FormInterface $form, array $options): void { $view->vars['columns'] = $options['columns']; $view->vars['minimum_rows'] = $options['minimum_rows']; } - /** - * @return string - */ public function getParent(): string { return CollectionType::class; diff --git a/src/lib/Form/Type/FieldType/MatrixEntryType.php b/src/lib/Form/Type/FieldType/MatrixEntryType.php index f22f8d4..8d83600 100644 --- a/src/lib/Form/Type/FieldType/MatrixEntryType.php +++ b/src/lib/Form/Type/FieldType/MatrixEntryType.php @@ -17,25 +17,16 @@ class MatrixEntryType extends AbstractType { - /** - * @return string - */ public function getName(): string { return $this->getBlockPrefix(); } - /** - * @return string - */ public function getBlockPrefix(): string { return 'ezplatform_fieldtype_ezmatrix_entry'; } - /** - * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver - */ public function configureOptions(OptionsResolver $resolver): void { $resolver->setDefined(['columns']); @@ -48,20 +39,11 @@ public function configureOptions(OptionsResolver $resolver): void parent::configureOptions($resolver); } - /** - * @param \Symfony\Component\Form\FormView $view - * @param \Symfony\Component\Form\FormInterface $form - * @param array $options - */ public function buildView(FormView $view, FormInterface $form, array $options): void { $view->vars['columns'] = $options['columns']; } - /** - * @param \Symfony\Component\Form\FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options): void { foreach ($options['columns'] as $column) { diff --git a/src/lib/Form/Type/FieldType/MatrixFieldType.php b/src/lib/Form/Type/FieldType/MatrixFieldType.php index 7fb3558..99d331d 100644 --- a/src/lib/Form/Type/FieldType/MatrixFieldType.php +++ b/src/lib/Form/Type/FieldType/MatrixFieldType.php @@ -48,21 +48,12 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefault('translation_domain', 'ibexa_matrix_fieldtype'); } - /** - * @param \Symfony\Component\Form\FormView $view - * @param \Symfony\Component\Form\FormInterface $form - * @param array $options - */ public function buildView(FormView $view, FormInterface $form, array $options): void { $view->vars['columns'] = $options['columns']; $view->vars['minimum_rows'] = $options['minimum_rows']; } - /** - * @param \Symfony\Component\Form\FormBuilderInterface $builder - * @param array $options - */ public function buildForm(FormBuilderInterface $builder, array $options): void { $builder diff --git a/src/lib/GraphQL/FieldValueResolver.php b/src/lib/GraphQL/FieldValueResolver.php index 1495515..5eadcf7 100644 --- a/src/lib/GraphQL/FieldValueResolver.php +++ b/src/lib/GraphQL/FieldValueResolver.php @@ -48,9 +48,12 @@ public function resolveMatrixFieldValue(object $item, string $fieldDefIdentifier ); } - /** @var \Ibexa\FieldTypeMatrix\FieldType\Value\RowsCollection $rows $rows */ - $rows = $content->getFieldValue($fieldDefIdentifier)->getRows(); - foreach ($rows as $row) { + /** @var \Ibexa\FieldTypeMatrix\FieldType\Value|null $fieldValue */ + $fieldValue = $content->getFieldValue($fieldDefIdentifier); + if ($fieldValue === null) { + return new RowsCollection(); + } + foreach ($fieldValue->getRows() as $row) { $silentRows[] = new SilentRow($row->getCells()); } diff --git a/src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php b/src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php index 1fcde5d..7f6744c 100644 --- a/src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php +++ b/src/lib/GraphQL/Schema/MatrixFieldDefinitionInputSchemaWorker.php @@ -23,7 +23,7 @@ public function __construct(NameHelper $nameHelper) $this->nameHelper = $nameHelper; } - public function work(Builder $schema, array $args) + public function work(Builder $schema, array $args): void { $typeName = $this->typeName($args); $schema->addType(new Builder\Input\Type($typeName, 'input-object')); @@ -42,7 +42,7 @@ public function work(Builder $schema, array $args) } } - public function canWork(Builder $schema, array $args) + public function canWork(Builder $schema, array $args): bool { return isset($args['ContentType']) @@ -53,7 +53,7 @@ public function canWork(Builder $schema, array $args) && !$schema->hasType($this->typeName($args)); } - private function typeName(array $args) + private function typeName(array $args): string { return $this->nameHelper->matrixFieldDefinitionInputType($args['ContentType'], $args['FieldDefinition']); } diff --git a/src/lib/GraphQL/Schema/MatrixFieldDefinitionMapper.php b/src/lib/GraphQL/Schema/MatrixFieldDefinitionMapper.php index 034d94d..c12a37c 100644 --- a/src/lib/GraphQL/Schema/MatrixFieldDefinitionMapper.php +++ b/src/lib/GraphQL/Schema/MatrixFieldDefinitionMapper.php @@ -8,7 +8,6 @@ namespace Ibexa\FieldTypeMatrix\GraphQL\Schema; -use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\Values\ContentType\ContentType; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Contracts\GraphQL\Schema\Domain\Content\Mapper\FieldDefinition\FieldDefinitionMapper; @@ -21,10 +20,7 @@ class MatrixFieldDefinitionMapper extends DecoratingFieldDefinitionMapper implem /** @var \Ibexa\FieldTypeMatrix\GraphQL\Schema\NameHelper */ private $nameHelper; - /** @var \Ibexa\Contracts\Core\Repository\ContentTypeService */ - private $contentTypeService; - - /* @var iterable<\Ibexa\FieldTypeMatrix\FieldType\Mapper\FieldTypeToContentTypeStrategyInterface> */ + /** @var iterable<\Ibexa\FieldTypeMatrix\FieldType\Mapper\FieldTypeToContentTypeStrategyInterface> */ private iterable $strategies; /** @@ -33,13 +29,11 @@ class MatrixFieldDefinitionMapper extends DecoratingFieldDefinitionMapper implem public function __construct( FieldDefinitionMapper $innerMapper, NameHelper $nameHelper, - ContentTypeService $contentTypeService, iterable $strategies ) { parent::__construct($innerMapper); $this->nameHelper = $nameHelper; - $this->contentTypeService = $contentTypeService; $this->strategies = $strategies; } diff --git a/src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php b/src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php index 99c491b..7808ce8 100644 --- a/src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php +++ b/src/lib/GraphQL/Schema/MatrixFieldDefinitionSchemaWorker.php @@ -23,7 +23,7 @@ public function __construct(NameHelper $nameHelper) $this->nameHelper = $nameHelper; } - public function work(Builder $schema, array $args) + public function work(Builder $schema, array $args): void { $typeName = $this->typeName($args); $schema->addType(new Builder\Input\Type($typeName, 'object')); @@ -42,7 +42,7 @@ public function work(Builder $schema, array $args) } } - public function canWork(Builder $schema, array $args) + public function canWork(Builder $schema, array $args): bool { return isset($args['ContentType']) @@ -53,7 +53,7 @@ public function canWork(Builder $schema, array $args) && !$schema->hasType($this->typeName($args)); } - private function typeName(array $args) + private function typeName(array $args): string { return $this->nameHelper->matrixFieldDefinitionType($args['ContentType'], $args['FieldDefinition']); } diff --git a/src/lib/GraphQL/Schema/NameHelper.php b/src/lib/GraphQL/Schema/NameHelper.php index 226b782..25c241d 100644 --- a/src/lib/GraphQL/Schema/NameHelper.php +++ b/src/lib/GraphQL/Schema/NameHelper.php @@ -14,7 +14,7 @@ class NameHelper { - public function matrixFieldDefinitionType(ContentType $contentType, FieldDefinition $fieldDefinition) + public function matrixFieldDefinitionType(ContentType $contentType, FieldDefinition $fieldDefinition): string { $caseConverter = new CamelCaseToSnakeCaseNameConverter(null, false); @@ -25,7 +25,7 @@ public function matrixFieldDefinitionType(ContentType $contentType, FieldDefinit ); } - public function matrixFieldDefinitionInputType(ContentType $contentType, FieldDefinition $fieldDefinition) + public function matrixFieldDefinitionInputType(ContentType $contentType, FieldDefinition $fieldDefinition): string { $caseConverter = new CamelCaseToSnakeCaseNameConverter(null, false);