Skip to content

Add @psalm-pure to count assertion methods#355

Open
devbanana wants to merge 2 commits intowebmozarts:masterfrom
devbanana:add-psalm-pure-to-count-methods
Open

Add @psalm-pure to count assertion methods#355
devbanana wants to merge 2 commits intowebmozarts:masterfrom
devbanana:add-psalm-pure-to-count-methods

Conversation

@devbanana
Copy link
Copy Markdown

Added @psalm-pure to count(), minCount(), maxCount(), and countBetween(). Most other methods have it already but this was being handled as maybe impure by PHPStan on a project I'm working on so thought I'd add it.

devbanana added 2 commits May 1, 2026 21:43
Mark count(), minCount(), maxCount(), and countBetween() as pure so
Psalm permits their use in pure contexts.
@zerkms
Copy link
Copy Markdown
Contributor

zerkms commented May 3, 2026

If a value implements Countable interface - nothing enforces Countable::count() to be pure.

@devbanana
Copy link
Copy Markdown
Author

If a value implements Countable interface - nothing enforces Countable::count() to be pure.

Yes I suppose that's a point. If that's a concern, perhaps a method just for asserting the count of strictly arrays would be accepted? Something like arrayCount() and similar.

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