[GH-ISSUE #130] Suggestion - stricter returns #60

Closed
opened 2026-02-25 20:32:19 +03:00 by kerem · 6 comments
Owner

Originally created by @ghost on GitHub (Oct 18, 2019).
Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/130

Just some food for thought!

Wouldn't make more sense to avoid mixed returns? E.g. bool|int when using verifyKey

And is this correct? https://github.com/antonioribeiro/google2fa/blob/master/src/Google2FA.php#L54 (int $startingTimestamp)

I found it when phpstan was giving me a lot of errors because I was treating verifyKey as return bool.

Originally created by @ghost on GitHub (Oct 18, 2019). Original GitHub issue: https://github.com/antonioribeiro/google2fa/issues/130 Just some food for thought! Wouldn't make more sense to avoid mixed returns? E.g. bool|int when using verifyKey And is this correct? https://github.com/antonioribeiro/google2fa/blob/master/src/Google2FA.php#L54 (int $startingTimestamp) I found it when phpstan was giving me a lot of errors because I was treating verifyKey as return bool.
kerem closed this issue 2026-02-25 20:32:19 +03:00
Author
Owner

@antonioribeiro commented on GitHub (Oct 21, 2019):

Should be fixed in 6.1.1. @Khyber3737 would you mind testing it again and closing this?

Thanks for reporting!

<!-- gh-comment-id:544542213 --> @antonioribeiro commented on GitHub (Oct 21, 2019): Should be fixed in 6.1.1. @Khyber3737 would you mind testing it again and closing this? Thanks for reporting!
Author
Owner

@ghost commented on GitHub (Oct 21, 2019):

I have verified that with --level 4 there are no errors. With --level max I get the usual errors that, from a library standpoint (not targeting >= 7.4, strict), makes perfect sense since it's just casting/coersion or a design decision. In hindsight since this library is used everywhere and is battle tested it would be difficult to change methods like findValidOTP and verifyKey. I will deal with that in a more proper opinionated layer.
Thank you! :)

<!-- gh-comment-id:544592947 --> @ghost commented on GitHub (Oct 21, 2019): I have verified that with `--level 4` there are no errors. With `--level max` I get the usual errors that, from a library standpoint (not targeting >= 7.4, strict), makes perfect sense since it's just casting/coersion or a design decision. In hindsight since this library is used everywhere and is battle tested it would be difficult to change methods like findValidOTP and verifyKey. I will deal with that in a more proper opinionated layer. Thank you! :)
Author
Owner

@antonioribeiro commented on GitHub (Oct 21, 2019):

Yeah, I tested it with level 4, sorry. I'm not really a PHPStan user, so I didn't know there were levels above it :/

<!-- gh-comment-id:544593623 --> @antonioribeiro commented on GitHub (Oct 21, 2019): Yeah, I tested it with level 4, sorry. I'm not really a PHPStan user, so I didn't know there were levels above it :/
Author
Owner

@antonioribeiro commented on GitHub (Oct 21, 2019):

@Khyber3737 Would you please test 6.1.2, please? I think I managed to make them all pass. I had to make one change in code, but it should not break things. It doesn't make sense let people pass $secret as null here:

image

<!-- gh-comment-id:544617376 --> @antonioribeiro commented on GitHub (Oct 21, 2019): @Khyber3737 Would you please test 6.1.2, please? I think I managed to make them all pass. I had to make one change in code, but it should not break things. It doesn't make sense let people pass $secret as null here: ![image](https://user-images.githubusercontent.com/3182864/67227464-af0b0d00-f40d-11e9-8090-7ab29e12d049.png)
Author
Owner

@ghost commented on GitHub (Oct 21, 2019):

[OK] No errors

👍

<!-- gh-comment-id:544629899 --> @ghost commented on GitHub (Oct 21, 2019): >[OK] No errors 👍
Author
Owner

@antonioribeiro commented on GitHub (Oct 21, 2019):

It's now on 7.0.0. I ended up causing a BC break, so I had to roll them back and draft a new major release.

<!-- gh-comment-id:544630833 --> @antonioribeiro commented on GitHub (Oct 21, 2019): It's now on 7.0.0. I ended up causing a BC break, so I had to roll them back and draft a new major release.
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/google2fa#60
No description provided.