From 793245c795f7a41491cfa3a3712638b7cfaa276e Mon Sep 17 00:00:00 2001 From: Nicolas Joubert Date: Fri, 9 Oct 2026 11:40:13 +0200 Subject: [PATCH] chore(quality) #143 [v6] Narrow native types that were never null: AbstractConfigurableTask::getOptions() and ProcessState::getContextualizedOptions() return array, CsvResource::$lineNumber and ProcessHistory::$startDate are not nullable. Improve PHPStan level from 7 to 8 Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 3 +++ docs/03-custom_tasks.md | 3 ++- phpstan.neon | 2 +- src/Filesystem/CsvResource.php | 2 +- src/Model/AbstractConfigurableTask.php | 4 ++-- src/Model/ProcessHistory.php | 2 +- src/Model/ProcessState.php | 4 ++-- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c761d9a1..b17e58fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ Latest * [#242](https://github.com/cleverage/process-bundle/issues/242) Fix InputFileReaderTask: an input that is not a non-empty string (e.g. `null`) throws an explicit `\UnexpectedValueException` (`No file path given as input`) instead of a PHP warning followed by a `TypeError`. Update documentation, add tests. * [#244](https://github.com/cleverage/process-bundle/issues/244) Fix MappingTransformer: a missing target property of a `\stdClass` destination (`initial_value` or `keep_input`) threw `Property '...' is not writable`, it is now added when the target is a simple property name (nested paths still throw). Update documentation, add tests. +## BC breaks +* [#143](https://github.com/cleverage/process-bundle/issues/143) Narrow native types that were never `null` in practice: `AbstractConfigurableTask::getOptions()` and `ProcessState::getContextualizedOptions()` return `array` (instead of `?array`), `CsvResource::$lineNumber` is an `int` and `ProcessHistory::$startDate` a `\DateTimeInterface` (instead of nullable types). Overrides of `getOptions()` must declare an `array` return type (e.g. cleverage/archive-process-bundle >= v2.3). Improve PHPStan level from 7 to 8. + v5.1 ----- diff --git a/docs/03-custom_tasks.md b/docs/03-custom_tasks.md index f0cacf9d..1e396e81 100644 --- a/docs/03-custom_tasks.md +++ b/docs/03-custom_tasks.md @@ -93,7 +93,8 @@ available in `CleverAge\ProcessBundle\Model\AbstractConfigurableTask`. Based on [Symfony's OptionsResolver Component](https://symfony.com/doc/current/components/options_resolver.html) this abstract class allows you to implement its `configureOptions` method to add your requirements, default values and normalizers. Options are resolved (once) during the task initialization, and can be read with `getOptions($state)` or -`getOption($state, $code)`. If the resolution fails during initialization, the error is logged and the options are +`getOption($state, $code)`. If you override `getOptions()`, it must return an `array` (it was typed `?array` before +v6.0). If the resolution fails during initialization, the error is logged and the options are resolved again (failing the process) when the task is first executed. Going on with the process after an initialization failure is deprecated since v5: in v6.0, the process will fail before any task is executed (see [initializable tasks](02-task_types.md#initializable-tasks)). diff --git a/phpstan.neon b/phpstan.neon index 3ac0c7ab..7318116b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 7 + level: 8 paths: - src - tests diff --git a/src/Filesystem/CsvResource.php b/src/Filesystem/CsvResource.php index 5220693f..92066f88 100644 --- a/src/Filesystem/CsvResource.php +++ b/src/Filesystem/CsvResource.php @@ -34,7 +34,7 @@ class CsvResource implements WritableStructuredFileInterface, SeekableFileInterf protected int $headerCount; - protected ?int $lineNumber = 1; + protected int $lineNumber = 1; protected bool $closed = false; diff --git a/src/Model/AbstractConfigurableTask.php b/src/Model/AbstractConfigurableTask.php index c4eb99ee..111f5f04 100644 --- a/src/Model/AbstractConfigurableTask.php +++ b/src/Model/AbstractConfigurableTask.php @@ -40,9 +40,9 @@ public function reset(): void } /** - * @return array|null + * @return array */ - protected function getOptions(ProcessState $state): ?array + protected function getOptions(ProcessState $state): array { if (null === $this->options) { $resolver = new OptionsResolver(); diff --git a/src/Model/ProcessHistory.php b/src/Model/ProcessHistory.php index de7c51e5..c1161dba 100644 --- a/src/Model/ProcessHistory.php +++ b/src/Model/ProcessHistory.php @@ -30,7 +30,7 @@ class ProcessHistory implements \Stringable protected string $processCode; - protected ?\DateTimeInterface $startDate; + protected \DateTimeInterface $startDate; protected ?\DateTimeInterface $endDate = null; diff --git a/src/Model/ProcessState.php b/src/Model/ProcessState.php index d34c2b29..195c1bbe 100644 --- a/src/Model/ProcessState.php +++ b/src/Model/ProcessState.php @@ -296,9 +296,9 @@ public function setContext(array $context): void } /** - * @return array|null + * @return array */ - public function getContextualizedOptions(): ?array + public function getContextualizedOptions(): array { if (!$this->contextualizedOptions) { $options = $this->getTaskConfiguration()