-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Improve type hinting in various classes #23811
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
base: 5.x-dev
Are you sure you want to change the base?
Conversation
1d6db1b to
5e516bd
Compare
| * @return mixed | ||
| * @template T of object | ||
| * @param class-string<T>|string $name Container entry name. | ||
| * @return ($name is class-string<T> ? T : mixed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should ensure that for something like StaticContainer('Piwik/Auth') an object of Piwik/Auth will be expected as returned value.
| { | ||
| $tasks = array(); | ||
|
|
||
| /** @var Tasks[] $pluginTasks */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect type hint, as findComponents actually returns class names not objects.
| public static function findAvailableSmsProviders() | ||
| { | ||
| /** @var SMSProvider[] $smsProviders */ | ||
| $smsProviders = Plugin\Manager::getInstance()->findMultipleComponents('SMSProvider', 'Piwik\Plugins\MobileMessaging\SMSProvider'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findMultipleComponents returns an array of class names, not objects.
| } | ||
|
|
||
| $auth = StaticContainer::get('Piwik\Auth'); | ||
| if ($auth && !$auth->getLogin() && method_exists($auth, 'getTokenAuth') && $auth->getTokenAuth()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If Piwik\Auth object can't be created an exception should be thrown, so checking for its existence should be unneeded.
| $string = $env->getRuntime(\Twig\Runtime\EscaperRuntime::class) | ||
| ->escape($string, $strategy, $charset, $autoescape); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
´twig_escape_filter´ is deprecated since a while already, so using an alternative way to achieve the same result.
| $this->twig->addFilter($percentage); | ||
| } | ||
|
|
||
| private function getProfessionalServicesAdvertising() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method was unused
| * @param int $key (don't care) | ||
| * @param string $path Piwik root | ||
| */ | ||
| public static function addPiwikPath(&$value, $key, $path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another unused method
|
|
||
| /** | ||
| * @template T of object | ||
| * @param class-string<T>|string $name Container entry name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add this too?
| * @param class-string<T>|string $name Container entry name. | |
| * @param class-string<T>|string $name Container entry name. | |
| * @throws NotFoundException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be "auto-detectable"
There was a problem hiding this 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 to understand what you mean here. There is no need to precise it since it’s auto-detectable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that's something we need to decide in general. I'm currently only trying to add type hints for those variables, where the code doesn't or can't define the explicitly. We can for sure consider to add doc blocks that contain everything, but that will also cause more maintaining work to keep everything up to date
Description
Checklist
Review