Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPstan improvements #12656

Merged
merged 5 commits into from Feb 9, 2023
Merged

PHPstan improvements #12656

merged 5 commits into from Feb 9, 2023

Conversation

timkelty
Copy link
Contributor

@timkelty timkelty commented Feb 8, 2023

ElementQuery return type hints

Short of properly returning static, this fixes static analysis (PHPstan) for ElementQuery setters.

Without this PR, the following code causes a PHPStan error, because Entry::slug returns ElementQuery (self) and not EntryQuery (static).

Entry::find()->slug('foo')->section('foo');
// Call to an undefined method craft\elements\db\ElementQuery::section().

\craft\db\Query::one

We return null, so should be typed as such. Prevents PHPstan complaining about comparisons like:

$query->one() === null

@timkelty timkelty requested a review from a team as a code owner February 8, 2023 18:58
@timkelty timkelty changed the title ElementQuery return type hints PHPstan improvements Feb 8, 2023
@brandonkelly brandonkelly changed the base branch from develop to 4.4 February 9, 2023 23:23
@brandonkelly brandonkelly merged commit 6f249c6 into 4.4 Feb 9, 2023
@brandonkelly brandonkelly deleted the phpstan-elementquery-return branch February 9, 2023 23:28
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.

None yet

2 participants