BehatPageObjectExtension icon indicating copy to clipboard operation
BehatPageObjectExtension copied to clipboard

Use generics annotations in getPage() to help static analysis

Open LuigiCardamone opened this issue 3 years ago • 0 comments

This PR solves the following issue.

If in a Context that extends PageObjectContext I write:

private function getLoginPage(): LoginPage
{
    return $this->getPage(LoginPage::class);
}

Both PHPStan and PHPStorm emit a warning. PHPStan warning message is: phpstan: Method Behat\Context\Ui\User\ChangePasswordContext::getLoginPage() should return Behat\Page\User\LoginPage but returns SensioLabs\Behat\PageObjectExtension\PageObject\Page.

My change allows static analysis to infer the right return type.

LuigiCardamone avatar Aug 03 '22 13:08 LuigiCardamone