Skip to content

auto-fix "Only booleans are allowed in an if condition" #316

@staabm

Description

@staabm

Feature request

when the native type of a property is known, we can auto-fix the "Only booleans are allowed in an if condition" phpstan-strict-error.

same is true for method-calls/function-calls etc. which have a native return-type.
I think this applies to any expression for which we know a non-union native type.

e.g.

class CoffeeBreak
{
	private array $arr;
	
	public function getDuration(): int {
		if ($this->arr) {
			
		}
	}
}

can get fixed to

class CoffeeBreak
{
	private array $arr;
	
	public function getDuration(): int {
		if (count($this->arr) !== 0) {
			
		}
	}
}

https://phpstan.org/r/5a9de50b-cc0c-47c9-81f8-fbe4d609ed4d

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions