sensiolabs / BehatPageObjectExtension

MIT License
117 stars 48 forks source link

Use generics annotations in getPage() to help static analysis #143

Closed LuigiCardamone closed 1 year ago

LuigiCardamone commented 2 years ago

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.

jakzal commented 1 year ago

Thank you @LuigiCardamone 🍺