parseSteps.php
Table of Contents
Functions
- parseSteps() : array<string|int, int>
- Parses a step-range expression into a sorted, deduplicated list of integer steps in `[1, $maxStep]`.
Functions
parseSteps()
Parses a step-range expression into a sorted, deduplicated list of integer steps in `[1, $maxStep]`.
parseSteps(string|null $input, int $maxStep) : array<string|int, int>
Designed for CLI commands that need to selectively run a subset of their
internal steps, e.g. integration test commands with an --step=N option.
Accepted syntax:
nullor''(empty) → all steps[1..maxStep](default).'all'or'*'→ same as above (explicit "all").'N'→[N](single step).'N1-N2'→[N1, N1+1, …, N2](closed range, inclusive).'-N'→[1, 2, …, N](open-left half range).'N-'→[N, N+1, …, maxStep](open-right half range).'A,B,C-D,E'→ comma-separated tokens, each parsed independently and merged. Order is irrelevant ; the result is always sorted with duplicates removed.
Whitespace around tokens / hyphens is allowed and stripped.
Invalid inputs raise InvalidArgumentException. The helper rejects:
- empty tokens (e.g.
'1,,3'), - non-numeric tokens (e.g.
'abc'), - bare
'-'(missing both bounds), - inverted ranges (
'6-4'), - out-of-range numbers (
< 1or> $maxStep).
Parameters
- $input : string|null
-
The step expression.
nulland''mean "all". - $maxStep : int
-
The maximum step number (inclusive). Used to expand
all/*and open-right ranges (N-), and to validate upper bounds.
Tags
Return values
array<string|int, int> —Sorted, deduplicated list of step numbers, all in [1, $maxStep].