Skip to content

Prepare 0.1 code for the 0.2 upgrade - #55

Merged
delacry merged 3 commits into
0.1.xfrom
bridge/0.1.8
Oct 10, 2026
Merged

delacry merged 3 commits into
0.1.xfrom
bridge/0.1.8

Conversation

@delacry

@delacry delacry commented Oct 10, 2026

Copy link
Copy Markdown
Member

Bridge release for 0.1.8: everything a 0.1 user needs to make their code work on both 0.1 and 0.2 before bumping the constraint.

onEach(), onEachKey(), onEachValue(). 0.2 makes forEach(), forEachKey() and forEachValue() return void and moves chaining to onEach*(). The onEach*() methods ship here already, so chained calls can switch now:

$users->forEach(fn (User $u) => $u->touch())->filter(...); // breaks on 0.2
$users->onEach(fn (User $u) => $u->touch())->filter(...);  // works on 0.1.8 and 0.2

They are real methods in CollectionLogic and MapLogic, but the interfaces declare them through @method tags rather than natively. Adding a method to an interface would break classes implementing it without the logic traits, which 0.2 may do but a 0.1 patch should not. Each interface narrows the return type the same way its forEach*() does, so PHPStan and IDEs keep the precise type along a chain (ImmutableList::onEach(): ImmutableList<E>, MutableTrackedMap::onEach(): MutableTrackedMap<K,V>&TrackedResult, ...).

forEach*() itself is unchanged and not deprecated: it stays in 0.2, only the return type changes, and PHP cannot tell whether a caller uses the result. After upgrading, PHPStan reports every affected call as Result of method ...::forEach() (void) is used.

mapOfPairs() without arguments. 0.2 makes $data required, matching mutableMapOfPairs(). Calling it with no arguments now triggers E_USER_DEPRECATED pointing to mapOf(); an explicit empty iterable stays silent.

UPGRADE-0.2.md. Lists every break with its replacement: forEach*() returning void, mapOfPairs() requiring its argument, MapLogic declaring $store (with exactly which $store declarations now fail and which do not), and the methods direct interface implementers must add. Also notes the zip() behaviour change and the new NoctudCollectionException marker. It should be cherry-picked onto 0.2.x as well.

The API reference and cheatsheet mention onEach*() and the upcoming forEach*() change.

Tests: onEach*() runtime tests ported from 0.2.x; tests/Type/OnEachTypeTest.php pins the narrowed return type on all 24 interfaces; mapOfPairs() with and without arguments.

0.2 makes forEach(), forEachKey() and forEachValue() return void and moves
chaining to onEach(), onEachKey() and onEachValue(). Ship the onEach*()
methods here already, so code chaining off forEach*() can switch while
still on 0.1 and then upgrade without further changes.

The methods live in CollectionLogic and MapLogic, delegating to forEach*().
The interfaces declare them through @method tags rather than natively:
adding a method to an interface would break classes implementing it
without the logic traits, which 0.2 is allowed to do but a 0.1 patch is
not. Each interface narrows the return type the same way its forEach*()
declaration does, so PHPStan and IDEs keep the precise type along a chain.

forEach*() itself is left untouched and not deprecated: it stays in 0.2,
only its return type changes, and PHP cannot tell whether a caller uses
the result. The API reference and cheatsheet point to onEach*() instead.
0.2 removes the default value of mapOfPairs()'s $data parameter, matching
mutableMapOfPairs(). Trigger E_USER_DEPRECATED when it is called without
arguments, pointing to mapOf() for an empty map. An explicit empty
iterable stays silent.
List the breaking changes between 0.1 and 0.2 with the replacement for
each: forEach*() returning void, mapOfPairs() requiring its argument, the
map logic traits declaring $store once, and the methods new interface
implementers must add. Note the zip() behaviour change and the new
NoctudCollectionException marker, and point to 0.1.8 for migrating ahead
of the upgrade.
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@delacry
delacry merged commit 53e6249 into 0.1.x Oct 10, 2026
6 checks passed
delacry added a commit that referenced this pull request Oct 10, 2026
List the breaking changes between 0.1 and 0.2 with the replacement for
each: forEach*() returning void, mapOfPairs() requiring its argument, the
map logic traits declaring $store once, and the methods new interface
implementers must add. Note the zip() behaviour change and the new
NoctudCollectionException marker, and point to 0.1.8 for migrating ahead
of the upgrade.

(cherry picked from 53e6249, #55 on 0.1.x)
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.

1 participant