Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

I'm using a Collection in an enum and trying to make phpstan understand that the enum is not empty.

I've tried it by defining that the array that goes into the Collection is non-empty via @method static non-empty-list<MyEnum> cases(), but that doesn't seem to work: https://phpstan.org/r/6892c3ee-247f-4b29-8af8-63431952af96

I've also tried with an extending "NonEmptyCollection" without result: https://phpstan.org/r/520b5d54-b0f4-4cc6-badb-3515c9e9ec7e

This is not an issue when the Collection is defined as non-empty: https://phpstan.org/r/683d781f-0710-4a91-9959-d1b7d413265b, but that class comes with the framework.

Is there a way to make this happen? What tags am I missing?

You must be logged in to vote

Replies: 1 comment

Comment options

It seems that this can be done in the following way: https://phpstan.org/r/1602e3ff-a46e-42b3-ad4e-0884a0856056
More specifically, you need to add @method T first() to NonEmptyCollection.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.