Repository navigation
Update type signatures to avoid warnings in PHP 8.1 - #172
someonewithpc wants to merge 1 commit into
Conversation
|
I'm wondering why the CI was not executed 😞 (I guess it is my fault) have you executed tests in earlier php versions? |
| * @param mixed $options | ||
| */ | ||
| public function __construct($name, $handler, $options = null) | ||
| final public function __construct($name, $handler, $options = null) |
There was a problem hiding this comment.
Is that one the warnings from phpstan?
I don't want to restrict the constructor. If someone wants to overwrite the constructors - I'm fine. So why to declare it final? If you still can overwrite the constructor (even more: it means the final keyword has no effect on constructors) I would especially not add this keyword.
In conclusion I would not add final for one or the other reason:
a) they should not be final
b) it might even be ignored from php
There was a problem hiding this comment.
PHPStan emits:
Unsafe usage of new static().
See: https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
But fair enough, I'll remove those
There was a problem hiding this comment.
ah, I see! Thats an intresting point. Maybe we should then use self instead. but please in a different PR if you want to solve it.
anyway it sounds odd to change the constructor and not the implementation of the static create method as it is just a syntax sugar to avoid the parenthesis around the new keyword: Option::create('h')->setDescription('Show help') instead of (new Option('h'))->setDescription('Show help')
| * @return mixed | ||
| */ | ||
| public function offsetGet($offset) | ||
| public function offsetGet($offset): mixed |
There was a problem hiding this comment.
mixed is not available in php 7 - is that a warning in php 8 now?
There was a problem hiding this comment.
we have to go with that backward compatible comment
https://php.watch/versions/8.1/ReturnTypeWillChange
I'm not able to run the tests in PHP 8.1, getting: But they run just fine in PHP 7.4: |
|
indeed it is an open issue on gitlab repo: https://gitlab.com/gitlab-org/gitlab/-/issues/5667 |
|
thx for your contribution. there is another PR to fix that issue and you forgot one of the final declarations. so I will go with that one. closed in favor of #173 |
Also fixes some errors reported by PHPStan