Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add phpstan assertions for last in Collection isEmpty and isNotEmpty #53107

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

bastien-phi
Copy link
Contributor

#51998 and #52184 added PHPStan assertions for Collection::first() in Collection::isEmpty() and Collection::isNotEmpty()

This PR adds the same for Collection::last() as it would be very useful

/**
 * @var Collection<int, string>
 */
$collection = new Collection(['laravel']);

if ($collection->isNotEmpty()) {
    // before this PR:
    \PHPStan\dumpType($collection->last()); // Dumped type: string|null
    
    // after this PR:
    \PHPStan\dumpType($collection->last()); // Dumped type: string
}

@taylorotwell taylorotwell merged commit 34f5ef6 into laravel:11.x Oct 10, 2024
33 checks passed
@bastien-phi bastien-phi deleted the phpstan_collection_empty branch October 10, 2024 19:23
@bastien-phi
Copy link
Contributor Author

Thanks !

timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 15, 2024
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.

2 participants