Skip to content

Fix types in method signatures and docblocks #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 29, 2021
Merged

Conversation

Naktibalda
Copy link
Member

I fixed many signatures that were stricter than necessary.

Closes #70

@Naktibalda Naktibalda force-pushed the type-fixes branch 3 times, most recently from 7989fdb to c7046b7 Compare December 25, 2021 19:48
Copy link
Member

@TavoNiievez TavoNiievez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay,
The changes that I would suggest in this PR have to do with the types of functions that are implemented from an interface.
Please verify that the signature of the methods corresponds exactly to each of the interfaces implemented in this class.
Taking a quick look I found for example that loadSessionSnapshot has a string $name parameter that is not typed yet, whereas you should remove all the : voids and : ?strings that you added in methods that implement an interface.
I am also curious about a matter. I didn't add a docblock in a function that implements an interface because I remember you once told me that doing that overwrites the documentation generated by robo. If that is the case, then you must also add the method description and the code example from the interface.

We should only change the typing of the methods that come from interfaces when we release a version that points and requires Codeception 5.
Even if I know that we are already breaking compatibility by modifying the other methods, we shouldn't mix up those changes. They must be different PR's as well as different versions.

@Naktibalda
Copy link
Member Author

Taking a quick look I found for example that loadSessionSnapshot has a string $name parameter that is not typed yet

I haven't typed it in my PR either.

The first build failed because I added type to parameter of _closeSession method.

PHP Fatal error: Declaration of Codeception\Module\WebDriver::_closeSession(?Facebook\WebDriver\Remote\RemoteWebDriver $webDriver = null): void must be compatible with Codeception\Lib\Interfaces\MultiSession::_closeSession($session = null)

https://github.com/Codeception/module-webdriver/runs/4633062856?check_suite_focus=true

so I removed it.

I guess that PHP does not complain about return type that is more specific than the interface.

@Naktibalda
Copy link
Member Author

Good point about documentation, I will check if we can use @inheritdoc

@Naktibalda
Copy link
Member Author

There is no inheritance, but I will try to implement it.

Copy link
Member

@TavoNiievez TavoNiievez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is ready for review again, but if you took my comments into account, it looks good to me this way.

@Naktibalda Naktibalda merged commit dbfb262 into master Dec 29, 2021
@Naktibalda Naktibalda deleted the type-fixes branch December 29, 2021 16:43
@@ -1676,7 +1685,7 @@ public function _loadSession($session)
*
* @api
*/
public function _backupSession()
public function _backupSession(): ?RemoteWebDriver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Naktibalda I just noticed that this method returns : array in Codeception 5
https://github.com/Codeception/Codeception/blob/a15b58781cbed2b3d5f21fd148cef474ee51101e/src/Codeception/Lib/Interfaces/MultiSession.php#L11
Should I remove the typing there?

@@ -3108,36 +3132,36 @@ protected function matchFirstOrFail($page, $selector): WebDriverElement
* $I->pressKey('#name', array('ctrl', 'a'), \Facebook\WebDriver\WebDriverKeys::DELETE); //=>''
* ```
*
* @param $char string|array Can be char or array with modifier. You can provide several chars.
* @param string|array|WebDriverBy $element
* @param array<string|string[]>$chars Can be char or array with modifier. You can provide several chars.
Copy link
Member

@ThomasLandauer ThomasLandauer Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Naktibalda According to this typehint, $chars always has to be an array; so the given example $I->pressKey('#page', 'a'); would be invalid. Where did you take this from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

moveMouseOver Method phpdoc saying only css selector string but accept string/array css selector
3 participants