Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Latest

## Changes
* [#197](https://github.com/cleverage/process-bundle/issues/197) Add missing tests: every Task and Transformer is now covered by unit tests. Remove the obsolete `tests.old` directory.
* [#143](https://github.com/cleverage/process-bundle/issues/143) Improve PHPStan configuration: remove all `ignoreErrors` and `@phpstan-ignore` comments (report unmatched ignored errors again), add missing iterable value types and generic types in PHPDoc, remove unreachable code in AbstractIterableOutputTask and InputAggregatorTask.

## Fixes
* [#143](https://github.com/cleverage/process-bundle/issues/143) Fix InputIteratorTask: an `\IteratorAggregate` input whose `getIterator()` does not return an `\Iterator` (e.g. another `\IteratorAggregate`) is iterated instead of failing with a `TypeError`. Update documentation, add tests.

v5.1
-----
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/tasks/input_iterator_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Task reference
Accepted inputs
---------------

`array`, `\Iterator` or `\IteratorAggregate`: any other type throws an `\UnexpectedValueException`
`array`, `\Iterator` or `\IteratorAggregate` (whatever `\Traversable` its `getIterator()` returns): any other type throws an `\UnexpectedValueException`

Possible outputs
----------------
Expand Down
11 changes: 0 additions & 11 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,5 @@ parameters:
- tests
excludePaths:
- src/Resources/tests/*
ignoreErrors:
- '#type has no value type specified in iterable type#'
- '#has parameter .* with no value type specified in iterable type#'
- '#has no value type specified in iterable type array#'
- '#configureOptions\(\) has no return type specified.#'
- '#configure\(\) has no return type specified#'
- '#process\(\) has no return type specified#'
- '#should return Iterator but returns Traversable#'
- '#Negated boolean expression is always false#'
- identifier: missingType.generics
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
treatPhpDocTypesAsCertain: false
3 changes: 3 additions & 0 deletions src/Command/ListProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public function processSorter(ProcessConfiguration $a, ProcessConfiguration $b):
return $a->getCode() <=> $b->getCode();
}

/**
* @param array{output: string} $message
*/
public function maxMessageLengthFilter(int $max, array $message): int
{
return max($max, \strlen($this->filterOutTags($message['output'])));
Expand Down
9 changes: 9 additions & 0 deletions src/Command/ProcessHelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* Try to find a best candidate for next display.
*
* @param array<string|null> $branches
* @param list<string> $taskList
*/
protected function findBestNextTask(
array $branches,
Expand Down Expand Up @@ -223,6 +226,8 @@ protected function getTaskChildrenCount(TaskConfiguration $task): int

/**
* Merge needed branches, display a task node, split following needed branches.
*
* @param array<string|null> $branches
*/
protected function resolveBranchOutput(
array &$branches,
Expand Down Expand Up @@ -442,6 +447,10 @@ static function ($branchTask, $i) use ($origin, $branches, $gapBranches, $final)
$this->writeBranches($output, $branches);
}

/**
* @param array<string|null> $branches
* @param string|iterable<string> $comment
*/
protected function writeBranches(
OutputInterface $output,
array $branches,
Expand Down
25 changes: 25 additions & 0 deletions src/Configuration/ProcessConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@
*/
class ProcessConfiguration
{
/**
* @var list<list<string>>|null
*/
protected ?array $dependencyGroups = null;

/**
* @var list<string>|null
*/
protected ?array $mainTaskGroup = null;

/**
* @param array<string, TaskConfiguration> $taskConfigurations
* @param array<string, mixed> $options
*/
public function __construct(
protected string $code,
protected array $taskConfigurations,
Expand All @@ -42,6 +52,9 @@ public function getCode(): string
return $this->code;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
Expand Down Expand Up @@ -106,6 +119,8 @@ public function getTaskConfiguration(string $taskCode): TaskConfiguration
* Group all task by dependencies.
*
* If one task depend from another, it should come after
*
* @return list<list<string>>
*/
public function getDependencyGroups(): array
{
Expand All @@ -130,6 +145,8 @@ public function getDependencyGroups(): array
* It may be defined by the entry_point, or the end_point or simply the first task.
*
* If one task depend from another, it should come after
*
* @return list<string>
*/
public function getMainTaskGroup(): array
{
Expand Down Expand Up @@ -195,6 +212,10 @@ public function checkCircularDependencies(): void

/**
* Cross all relations of a task to find all dependencies, and append them to the given array.
*
* @param list<string> $dependencies
*
* @return list<string>
*/
protected function buildDependencies(TaskConfiguration $taskConfig, array &$dependencies = []): array
{
Expand Down Expand Up @@ -222,6 +243,10 @@ protected function buildDependencies(TaskConfiguration $taskConfig, array &$depe

/**
* Sort the tasks by dependencies.
*
* @param list<string> $dependencies
*
* @return list<string>
*/
protected function sortDependencies(array $dependencies): array
{
Expand Down
17 changes: 17 additions & 0 deletions src/Configuration/TaskConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class TaskConfiguration

protected bool $logErrors;

/**
* @param array<string, mixed> $options
* @param list<string> $outputs
* @param list<string> $errorOutputs
*/
public function __construct(
protected string $code,
protected string $serviceReference,
Expand Down Expand Up @@ -93,6 +98,9 @@ public function getHelp(): string
return $this->help;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
Expand All @@ -107,11 +115,17 @@ public function getOption(string $code, mixed $default = null): mixed
return $default;
}

/**
* @return list<string>
*/
public function getOutputs(): array
{
return $this->outputs;
}

/**
* @return list<string>
*/
#[\Deprecated(message: 'Use getErrorOutputs method instead')]
public function getErrors(): array
{
Expand All @@ -120,6 +134,9 @@ public function getErrors(): array
return $this->getErrorOutputs();
}

/**
* @return list<string>
*/
public function getErrorOutputs(): array
{
return $this->errorOutputs;
Expand Down
7 changes: 7 additions & 0 deletions src/Context/ContextualOptionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ContextualOptionResolver
/**
* Basic value inference
* Replaces "{{ key }}" by context[key].
*
* @param array<string, mixed> $context
*/
public function contextualizeOption(mixed $value, array $context): mixed
{
Expand Down Expand Up @@ -46,6 +48,11 @@ public function contextualizeOption(mixed $value, array $context): mixed

/**
* Replace all contextualized values from options.
*
* @param array<string, mixed> $options
* @param array<string, mixed> $context
*
* @return array<string, mixed>
*/
public function contextualizeOptions(array $options, array $context): array
{
Expand Down
6 changes: 6 additions & 0 deletions src/Event/ConsoleProcessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
*/
class ConsoleProcessEvent extends Event
{
/**
* @param array<string, mixed> $processContext
*/
public function __construct(
private readonly InputInterface $consoleInput,
private readonly OutputInterface $consoleOutput,
Expand All @@ -45,6 +48,9 @@ public function getProcessInput(): mixed
return $this->processInput;
}

/**
* @return array<string, mixed>
*/
public function getProcessContext(): array
{
return $this->processContext;
Expand Down
6 changes: 6 additions & 0 deletions src/Event/ProcessEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class ProcessEvent extends Event

final public const EVENT_PROCESS_FAILED = 'cleverage_process.fail';

/**
* @param array<string, mixed> $processContext
*/
public function __construct(
protected string $processCode,
protected mixed $processInput = null,
Expand All @@ -50,6 +53,9 @@ public function getProcessOutput(): mixed
return $this->processOutput;
}

/**
* @return array<string, mixed>
*/
public function getProcessContext(): array
{
return $this->processContext;
Expand Down
6 changes: 5 additions & 1 deletion src/EventListener/DataQueueEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace CleverAge\ProcessBundle\EventListener;

use CleverAge\ProcessBundle\Event\EventDispatcherTaskEvent;
use CleverAge\ProcessBundle\Model\ProcessState;

/**
* Class DataQueueEventListener
Expand All @@ -23,7 +24,7 @@
class DataQueueEventListener
{
/**
* @var \SplQueue[]
* @var array<string, \SplQueue<ProcessState>>
*/
protected array $queues = [];

Expand All @@ -33,6 +34,9 @@ public function pushData(EventDispatcherTaskEvent $event): void
$queue->push(clone $event->getState());
}

/**
* @return \SplQueue<ProcessState>
*/
public function getQueue(string $processName): \SplQueue
{
if (!\array_key_exists($processName, $this->queues)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Exception/InvalidProcessConfigurationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
class InvalidProcessConfigurationException extends \UnexpectedValueException implements ProcessExceptionInterface
{
/**
* @param list<string> $mainTaskList
*/
public static function createNotInMain(
ProcessConfiguration $processConfiguration,
TaskConfiguration $taskConfig,
Expand Down
3 changes: 3 additions & 0 deletions src/ExpressionLanguage/PhpFunctionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
*/
class PhpFunctionProvider implements ExpressionFunctionProviderInterface
{
/**
* @param list<string> $functions
*/
public function __construct(
protected array $functions,
) {
Expand Down
8 changes: 4 additions & 4 deletions src/Filesystem/CsvFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
class CsvFile extends CsvResource
{
/**
* @param string $filePath Also accept a resource
* @param string $delimiter CSV delimiter
* @param ?array $headers Leave null to read the headers from the file
* @param string $mode Same parameter as the mode in the fopen function (r, w, a, etc.)
* @param string $filePath Also accept a resource
* @param string $delimiter CSV delimiter
* @param list<string>|null $headers Leave null to read the headers from the file
* @param string $mode Same parameter as the mode in the fopen function (r, w, a, etc.)
*/
public function __construct(
protected $filePath,
Expand Down
Loading
Loading