Skip to content

Conversation

@pindab0ter
Copy link

What:

  • Bug Fix
  • New Feature

Description:

When extending expect(), we are met with phpstan: Undefined variable: $this. This is resolved by specifying what $this will refer to in the closure.

Example of what this PR fixes:

expect()->extend('toBeTrashed', function () {
    Assert::assertThat(
        $this->value, // phpstan: Undefined variable: $this
        new class () extends Constraint {
            public function matches(mixed $other): bool
            {
                if (!($other instanceof Model && method_exists($other, 'trashed'))) {
                    throw new InvalidArgumentException('Can only be used on Models, not on queries.');
                }

                return $other->trashed();
            }

            public function toString(): string
            {
                return 'is trashed';
            }
        }
    );

    return $this; // phpstan: Undefined variable: $this
});

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.

1 participant