[v6] #234 - ArrayFirstTransformer: restore the meaning of allow_not_iterable - #235
Draft
njoubert-cleverage wants to merge 1 commit into
Draft
njoubert-cleverage wants to merge 1 commit into
njoubert-cleverage wants to merge 1 commit into
Conversation
…the allow_not_iterable option, inverted since v4.0: by default a non-iterable input throws an UnexpectedValueException, with allow_not_iterable: true it is returned unchanged. Traversable inputs return their first element. Update documentation, add tests. BREAKING CHANGE: to be released in v6.0. Set allow_not_iterable: true to keep the former default behaviour. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #234. To be merged for v6.0 only (breaking change): this PR is a draft, attached to the v6.0 milestone.
The
allow_not_iterableoption ofArrayFirstTransformeris inverted since v4.0 (refactoring of #142): by default a non-iterable input is returned unchanged, andallow_not_iterable: truethrows a\TypeError. This PR restores the meaning it had in v2 / v3:allow_not_iterable: false(default): a non-iterable input throws an explicit\UnexpectedValueException;allow_not_iterable: true: a non-iterable input is returned unchanged;Traversableinputs return their first element (instead ofreset()on an object, which returns its first property and is deprecated since PHP 8.1),falseif empty, as for an empty array;allow_not_iterablemust be abool;ArrayFirstTransformerTestis rewritten (the previous tests asserted the inverted behaviour), the reference documentation and the CHANGELOG (new BC breaks section inLatest) are updated.The rewritten tests fail on
mainand pass with this change. PHPUnit (with coverage), PHPStan, PHP-CS-Fixer and Rector pass, and the changed files are valid PHP 8.2.When merging for v6.0: move the CHANGELOG entry to the v6.0 section (the
Latestsection may have been released as a v5.x in the meantime).Requirements
Breaking changes
Major: with the default options, a non-iterable input now throws an
\UnexpectedValueExceptioninstead of being returned unchanged. Setallow_not_iterable: trueto keep the former default behaviour.array_firstis not used by the other cleverage bundles nor by the demo project.🤖 Generated with Claude Code