Skip to content

Make Arrays::flatten type-correct - #70

Merged
frankdekker merged 6 commits into
123inkt:masterfrom
RubenKluft:generic_flatten
Aug 27, 2026
Merged

frankdekker merged 6 commits into
123inkt:masterfrom
RubenKluft:generic_flatten

Conversation

@RubenKluft

Copy link
Copy Markdown
Contributor

Make Arrays::flatten generic
Adds Phpstan extension to make this possible, as phpstan does not support recursive type definition, an extension is required

Adds Phpstan extension to make this possible
Copilot AI lite review requested due to automatic review settings August 26, 2026 13:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ArraysFlattenReturnExtension to compute flattened leaf item types for Arrays::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.

Comment thread src/PHPStan/Extension/ArraysFlattenReturnExtension.php
Comment thread tests/Integration/PHPStan/data/ArraysFlattenAssertions.php
Comment thread tests/Integration/PHPStan/data/ArraysFlattenAssertions.php Outdated
@frankdekker frankdekker changed the title Make Arrays::flatten generic Make Arrays::flatten type-correct Aug 27, 2026
@frankdekker
frankdekker self-requested a review August 27, 2026 10:58
@frankdekker
frankdekker merged commit 471d3f7 into 123inkt:master Aug 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants