Open
Conversation
Tighten type information across the helper utilities so key and value types are preserved more accurately through pipelines when analysed with PHPStan. Add type assertions for the affected helpers and move the most advanced higher-order signatures into a PHPStan stub file so the runtime code can stay small, predictable, and function-first. # Conflicts: # src/pipe.php
7b7b574 to
e058917
Compare
Contributor
|
Thank you! I will have a look at this later in the weekend. |
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.
Why
I’m opening this PR because I really like the clean, composable
implementation this library provides. It helps reduce repeated inline and
static closures in my pipelines and makes pipe-heavy code much nicer to
read.
While using it in projects with PHPStan enabled, I ran into a practical
issue: some helpers did not preserve types accurately enough through the
pipeline for static analysis. That meant I couldn’t use all of the
utilities as-is in linted codebases, especially helpers like
str_replace()andpreg_replace(), where the runtime behavior was finebut the inferred types were too loose.
This PR is intended to improve that experience so the library’s ergonomic
runtime API is matched by more accurate type preservation in tools like
PHPStan.
Goal
Improve the project’s PHPStan-facing type hints so the utility helpers
preserve types more accurately through pipelines.
What changed
array_map,iterable_map,iterable_filter,collect,array_nth,and
iterable_nthstr_replace()andpreg_replace()where preserving the subject type is especially important in real
pipelines
the intended helper behavior
that are difficult to express cleanly on the runtime wrappers
themselves
Why the stub file exists
The library philosophy is to keep helpers as small unary functions with
minimal runtime machinery. Some of the stronger higher-order PHPStan
signatures are better expressed in analysis-only stubs than in the
runtime implementation.
This keeps the runtime code simple and aligned with the repo’s design,
while still giving users accurate type preservation when using tools like
PHPStan.
Validation
composer analyseAuthorship
This PR was produced with help from both Claude and Codex, with human
input, changes, and review throughout. This is PR started with a late
night claude mobile session on my way home from work, hence the
branch name.