Skip to content

Improper handling of discrepancy between PHPDoc and method header #3534

@thesailorbreton

Description

@thesailorbreton

In the below code, there is an error in the PHPDoc, the return type of the terminate() method in PHPDocs is not correct

https://phpstan.org/r/2ad3775b-590e-4f0f-a933-3af59e3cdf3d

<?php declare(strict_types = 1);


class MyClassWithErrorInPHPDocs{
	
	/**
     * The PHP docs return type below is wrong as it returns a bool
     * @return void
     */
    public function terminate(): bool
    {
        return true;
    }
	
	public function foo()
{
		if($this->terminate()){
			echo "C'est fini";
		}
	}
}

The error message generated for level 0 and 1 is :
Result of method MyClassWithErrorInPHPDocs::terminate() (void) is used.

From level 2 onwards you also get:
PHPDoc tag @return with type void is incompatible with native type bool.

I believe that given level 0 and 1 do not check PHPDoc, PHPStan should not report any error for level 0 and 1 as the header of the terminate() method is that it returns a bool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions