BooleansInCondition doesn't respect checkExplicitMixed/checkImplicitMixed config

Open
#253 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
devtools

Research direction

Start with src/Rules/BooleansInConditions/BooleanRuleHelper.php, especially the mixed-type handling around lines 25–27, and compare the two linked PHPStan reproductions. Determine how checkExplicitMixed and checkImplicitMixed should affect the rule, then verify that both explicit and implicit mixed conditions follow the selected behavior.

Written by the indexing model from the issue text.

Description

Booleans in condition report explicitMixed in level 7
https://phpstan.org/r/954e86c5-1a77-43e9-a4c7-c96f9c66b1fe

But doesn't report implicitMixed in level 10
https://phpstan.org/r/865a7467-a5f4-46c3-a95f-b592db7e2f9e

This is because BooleanRuleHelper has a custom behavior for mixed
https://github.com/phpstan/phpstan-strict-rules/blob/a4a6a08bd4a461e516b9c3b8fdbf0f1883b34158/src/Rules/BooleansInConditions/BooleanRuleHelper.php#L25-L27

I think it should rely on explicitMixed/implicitMixed config instead.

Option 1:
Chaning nothing

Option2:
Using both checkExplicitMixed/checkImplicitMixed config

if ($type instanceof MixedType) {
     if ($type->isExplicitMixed()) {
           return !$this->checkExplicitMixed;
     } else {
           return !$this->checkImplicitMixed;
     }
}

Option3:
Keeping the behavior for explicitMixed but allow to report implicitMixed.

if ($type instanceof MixedType) {
     return !$type->isExplicitMixed() && !$this->checkImplicitMixed;
}

I would go with option 2, but it's your call @ondrejmirtes

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-strict-rules

All issues in phpstan/phpstan-strict-rules

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.