Weak comparison detection
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
Research direction
Start with the related PHPStan issue #791 and the current weak-comparison rule coverage. Reproduce both PHP examples, then trace the rule that evaluates nullable values in boolean conditions. Done means reporting the nullable integer case while leaving the nullable DateTime case without an error.
Written by the indexing model from the issue text.
Description
Related: https://github.com/phpstan/phpstan/issues/791
A weak comparison error should be thrown for such case:
<?php declare(strict_type=1);
function getCount(): ?int
{
return 0 === rand(1, 5) % 5 ? 42 : null;
}
if (!getCount()) {
echo 'test';
}
Because 0 and null will go to the same result.
But this case must not rise an error:
<?php declare(strict_type=1);
function getUpdatedAt(): ?\DateTime
{
return 0 === rand(1, 5) % 5 ? new \DateTime('now') : null;
}
if (!getUpdatedAt()) {
echo 'test';
}
Because it's currently fine, no confusable value can be return here.
- Dominant language
- PHP
- Stars
- 709
- Forks
- 62
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 3
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phpstan/phpstan-strict-rules
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-strict-rules#317 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phpstan/phpstan-strict-rules#316 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 52/100
phpstan/phpstan-strict-rules#298 · 2 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
phpstan/phpstan-strict-rules#289 · 1 comment ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
phpstan/phpstan-strict-rules#283 · 6 comments ·
All issues in phpstan/phpstan-strict-rules
Similar issues
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nextcloud/fulltextsearch#1011 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
phpstan/phpstan-doctrine#794 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Automattic/static-site-importer#1767 ·