Skip to content

Commit

Permalink
Mark some methods as as impure for PHPStan
Browse files Browse the repository at this point in the history
By default, PHPSTan considers assumes that all methods that return a
value are pure, meaning they have no side effects.

While we could configure PHPStan so it is consistent with Psalm, we do
not know how downstream projects are configured and should assume they
rely on the default behavior.

See https://phpstan.org/blog/remembering-and-forgetting-returned-values

Both moveNext() and glimpse() have side effects in that they modify
properties, and are therefore marked as impure.
  • Loading branch information
greg0ire committed Jul 4, 2023
1 parent 84a527d commit ba2f368
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/AbstractLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public function isNextTokenAny(array $types)
*
* @return bool
*
* @phpstan-impure
* @psalm-assert-if-true !null $this->lookahead
*/
public function moveNext()
Expand Down Expand Up @@ -220,6 +221,8 @@ public function peek()
*
* @return mixed[]|null The next token or NULL if there are no more tokens ahead.
* @psalm-return Token<T, V>|null
*
* @phpstan-impure
*/
public function glimpse()
{
Expand Down

0 comments on commit ba2f368

Please sign in to comment.