Skip to content

Add assert is list - #66

Merged
frankdekker merged 11 commits into
masterfrom
Add-assert-is-list
Apr 23, 2026
Merged

Add assert is list#66
frankdekker merged 11 commits into
masterfrom
Add-assert-is-list

Conversation

@frankdekker

@frankdekker frankdekker commented Apr 18, 2026

Copy link
Copy Markdown
Member

Adds Assert::isList to assert an array is of type list<mixed>

Added phpstan extension to preserve value type information, as this was not possible with phpstan standard docblock notation.

Scenarios:

  • in: mixed, out: list<mixed>
  • in: int[], out: list<int>
  • in: array<int|string..>, out: list<int|string..>

Security advisories

Had to remove PHPUnit 10 + 11 due to:

Root composer.json requires phpunit/phpunit ^10.2 || ^11.0, found phpunit/phpunit[10.2.0, ..., 10.5.63, 11.0.0, ..., 11.5.55] but these were not loaded, because they are affected by security advisories. To ignore the advisories, add ("PKSA-5jz8-6tcw-pbk4") to the audit "ignore" config.

Copilot AI review requested due to automatic review settings April 18, 2026 08:00

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

Adds a new Assert::isList() assertion to complement existing Assert::isArray() behavior, and introduces a PHPStan dynamic return type extension so isList() preserves element type information as list<V> during static analysis.

Changes:

  • Added Assert::isList(mixed $value): array runtime assertion using array_is_list().
  • Added a PHPStan DynamicStaticMethodReturnTypeExtension + integration tests to infer list<V> while preserving value types.
  • Updated configuration (extension.neon) and documentation (README.md) to expose/register the new feature.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Assert.php Adds Assert::isList() runtime assertion method.
src/PHPStan/Extension/AssertIsListReturnExtension.php Adds PHPStan dynamic return type extension for Assert::isList().
extension.neon Registers the new PHPStan extension service.
tests/Unit/AssertTest.php Adds unit tests for isList() success and failure modes.
tests/Integration/PHPStan/AssertIsListExtensionTest.php Adds PHPStan type-inference test harness for the new extension.
tests/Integration/PHPStan/data/AssertIsListAssertions.php Provides assertType() cases validating inferred list/value types.
README.md Documents isList in the Assert method list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Assert.php
Comment thread src/PHPStan/Extension/AssertIsListReturnExtension.php
@frankdekker
frankdekker requested a review from bram123 April 18, 2026 08:40
@frankdekker
frankdekker merged commit 1b57d0a into master Apr 23, 2026
8 checks passed
@frankdekker
frankdekker deleted the Add-assert-is-list branch April 23, 2026 09:03
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