-
Notifications
You must be signed in to change notification settings - Fork 428
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
use positive-int in array_count_values() #645
Conversation
Error is unrelated |
resources/functionMap.php
Outdated
@@ -263,7 +263,7 @@ | |||
'array_chunk' => ['array[]', 'input'=>'array', 'size'=>'int', 'preserve_keys='=>'bool'], | |||
'array_column' => ['array', 'array'=>'array', 'column_key'=>'mixed', 'index_key='=>'mixed'], | |||
'array_combine' => ['array|false', 'keys'=>'array', 'values'=>'array'], | |||
'array_count_values' => ['int[]', 'input'=>'array'], | |||
'array_count_values' => ['array<int|string, 0|positive-int>', 'input'=>'array'], |
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.
just do array<0|positive-int>
- the difference is that the key will be BenevolentUnionType
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.
Of course a dynamic return type extension would be nice and precise :)
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.
Of course a dynamic return type extension would be nice and precise :)
Agree. Was just hunting low hanging fruits in the signature file
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.
BenevolentUnionType
i read this classname in a lot of spots, but have no idea what it is/why its better/different then e.g. array-key or int|string
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.
The difference is that if you have array<string>
then:
foreach ($array as $k => $v) {
// $k is BenevolentUnionType of int|string
$this->requireString($k); // PHPStan does not complain
$this->requireInt($k); // PHPStan does not complain
$this->requireStdClass($k); // PHPStan complains on level 5+
}
But with array<int|string, string>
:
foreach ($array as $k => $v) {
// $k is UnionType of int|string
$this->requireString($k); // PHPStan complains on level 7+
$this->requireInt($k); // PHPStan complains on level 7+
$this->requireStdClass($k); // PHPStan complains on level 5+
$this->requireIntOrString($k); // PHPStan does not complain
}
Thank you! |
No description provided.