Make Arrays::flatten type-correct - #70
Merged
Merged
Conversation
Adds Phpstan extension to make this possible
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a PHPStan dynamic static method return type extension to provide more precise (recursive) generic type inference for DR\Utils\Arrays::flatten(), since PHPStan can’t express the desired recursive generic natively.
Changes:
- Adds
ArraysFlattenReturnExtensionto compute flattened leaf item types forArrays::flatten()calls. - Updates
Arrays::flatten()PHPDoc to document a generic template and reference the extension for precise typing. - Adds unit + integration PHPStan type inference tests and registers the extension via
extension.neon(with baseline updates).
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Unit/PHPStan/Extension/ArraysFlattenReturnExtensionTest.php | Adds a basic unit test for the new return-type extension. |
| tests/Integration/PHPStan/ArraysFlattenReturnExtensionTest.php | Adds PHPStan type inference integration test harness for flatten assertions. |
| tests/Integration/PHPStan/data/ArraysFlattenAssertions.php | Adds type assertions that validate inferred return types for various flatten inputs. |
| src/PHPStan/Extension/ArraysFlattenReturnExtension.php | Implements dynamic return type inference for Arrays::flatten(). |
| src/Arrays.php | Updates flatten() PHPDoc to a generic template and references the extension. |
| phpstan-baseline.neon | Baselines new PHPStan API deprecation notices introduced by the extension. |
| extension.neon | Registers the new PHPStan return type extension as a service. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
baseline coverage for unrelated TypeNarrower
frankdekker
self-requested a review
August 27, 2026 10:58
frankdekker
approved these changes
Aug 27, 2026
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.
Make Arrays::flatten generic
Adds Phpstan extension to make this possible, as phpstan does not support recursive type definition, an extension is required