Skip to content

Conversation

gharlan
Copy link
Member

@gharlan gharlan commented Aug 30, 2025

SplFixedArray uses T|null in return types because value can be null if an offset is unset or if the size does not match the number of elements. (https://github.com/phpstan/phpstan-src/blob/c5d7128a8183efd61e73558626faf549e52db65a/stubs/ArrayObject.stub#L91-L93)

But our Tokens class takes care of it and always ensures correct size and indexes, so that these methods never return null instead of Token.

So I suggest to override these return types.

At the moment it resolves only some ignored errors. But in higher PHPStan level it would resolve 342 new errors.

@coveralls
Copy link

coveralls commented Aug 30, 2025

Coverage Status

coverage: 94.693%. remained the same
when pulling 5bc9caf on gharlan:splfixedarray
into 8444566 on PHP-CS-Fixer:master.

@gharlan gharlan merged commit f6b7742 into PHP-CS-Fixer:master Sep 1, 2025
31 checks passed
@gharlan gharlan deleted the splfixedarray branch September 1, 2025 08:10
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.

3 participants