Skip to content

[v6] #234 - ArrayFirstTransformer: restore the meaning of allow_not_iterable - #235

Draft
njoubert-cleverage wants to merge 1 commit into
mainfrom
234
Draft

njoubert-cleverage wants to merge 1 commit into
mainfrom
234

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

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_iterable option of ArrayFirstTransformer is inverted since v4.0 (refactoring of #142): by default a non-iterable input is returned unchanged, and allow_not_iterable: true throws 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;
  • Traversable inputs return their first element (instead of reset() on an object, which returns its first property and is deprecated since PHP 8.1), false if empty, as for an empty array;
  • allow_not_iterable must be a bool;
  • ArrayFirstTransformerTest is rewritten (the previous tests asserted the inverted behaviour), the reference documentation and the CHANGELOG (new BC breaks section in Latest) are updated.

The rewritten tests fail on main and 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 Latest section may have been released as a v5.x in the meantime).

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

Major: with the default options, a non-iterable input now throws an \UnexpectedValueException instead of being returned unchanged. Set allow_not_iterable: true to keep the former default behaviour. array_first is not used by the other cleverage bundles nor by the demo project.

🤖 Generated with Claude Code

…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>
@njoubert-cleverage njoubert-cleverage added this to the v6.0 milestone Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrayFirstTransformer: the allow_not_iterable option is inverted since v4.0

1 participant