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
Checks on array keys arent added to the type information #2911
Comments
You could rewrite the logic so that it's more apparent to PHPStan what's going on. Something like: // ... create $removeValue and $limitValue however you want...
return [
'remove' => $removeValue,
'limit' => $limitValue,
]; |
Didn't think of just rewriting the method 😅. Shouldn't be too hard in this case. |
I'm running into a similar issue when using |
Another simplified example spotted today: https://phpstan.org/r/74d26602-a918-47a3-8aba-1db613ddeeef |
@BackEndTea PHPStan now reports different result with your code snippet: @@ @@
-64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit is never read, only written.
+64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>&nonEmpty. Full report
|
@BackEndTea PHPStan now reports different result with your code snippet: @@ @@
+17: Method ArrayItemRemoval::getResultSettings() is unused.
28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>. Full report
|
@eigan PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $array of function bar expects array('bar' => string), array given.
+10: Parameter #1 $array of function bar expects array('bar' => string), array&nonEmpty given. Full report
|
@BackEndTea PHPStan now reports different result with your code snippet: @@ @@
-64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+PHP 8.0 (3 errors)
+==========
+
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit is never read, only written.
+64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>&nonEmpty.
+
+PHP 7.1 – 7.4 (8 errors)
+==========
+
+ 9: Method MutatorConfig::getMutatorSettings() return type has no value type specified in iterable type array.
+25: Property ArrayItemRemoval::$remove has no typehint specified.
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit has no typehint specified.
+30: Property ArrayItemRemoval::$limit is never read, only written.
+45: Method ArrayItemRemoval::getResultSettings() has parameter $settings with no value type specified in iterable type array.
+45: Method ArrayItemRemoval::getResultSettings() return type has no value type specified in iterable type array.
+70: Method ArrayItemRemoval::configException() has parameter $settings with no value type specified in iterable type array. Full reportPHP 8.0 (3 errors)
PHP 7.1 – 7.4 (8 errors)
|
@BackEndTea PHPStan now reports different result with your code snippet: @@ @@
-28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+PHP 8.0 (3 errors)
+==========
+
+17: Method ArrayItemRemoval::getResultSettings() has parameter $settings with no value type specified in iterable type array.
+17: Method ArrayItemRemoval::getResultSettings() is unused.
+17: Method ArrayItemRemoval::getResultSettings() return type has no value type specified in iterable type array.
+
+PHP 7.4 (2 errors)
+==========
+
+17: Method ArrayItemRemoval::getResultSettings() is unused.
+28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+
+PHP 7.1 – 7.3 (3 errors)
+==========
+
+17: Method ArrayItemRemoval::getResultSettings() has parameter $settings with no value type specified in iterable type array.
+17: Method ArrayItemRemoval::getResultSettings() is unused.
+17: Method ArrayItemRemoval::getResultSettings() return type has no value type specified in iterable type array. Full reportPHP 8.0 (3 errors)
PHP 7.4 (2 errors)
PHP 7.1 – 7.3 (3 errors)
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+17: Method ArrayItemRemoval::getResultSettings() is unused.
+28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>&nonEmpty. Full report
|
@bbatsche After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-19: Method ConfigWrapper::toArray() should return array('foo' => string, 'fizz' => string) but returns array.
+No errors |
@bbatsche After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-19: Method ConfigWrapper::toArray() should return array('foo' => string, 'fizz' => string) but returns array.
+-1: Internal error: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule::findMethod(): Argument #2 ($classReflection) must be of type PHPStan\Reflection\ClassReflection, null given, called in /var/task/vendor/phpstan/phpstan-strict-rules/src/Rules/Methods/WrongCaseOfInheritedMethodRule.php on line 40
+Run PHPStan with --debug option and post the stack trace to:
+https://github.com/phpstan/phpstan/issues/new?template=Bug_report.md Full report
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit is never read, only written.
+64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns non-empty-array<string, mixed>. Full report
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+17: Method ArrayItemRemoval::getResultSettings() is unused.
+28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns non-empty-array<string, mixed>. Full report
|
@eigan After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $array of function bar expects array('bar' => string), array given.
+10: Parameter #1 $array of function bar expects array('bar' => string), non-empty-array given. Full report
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit is never read, only written.
+64: Method ArrayItemRemoval::getResultSettings() should return array{remove: string, limit: int} but returns non-empty-array<string, mixed>. Full report
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+17: Method ArrayItemRemoval::getResultSettings() is unused.
+28: Method ArrayItemRemoval::getResultSettings() should return array{remove: string, limit: int} but returns non-empty-array<string, mixed>. Full report
|
@bbatsche After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-19: Method ConfigWrapper::toArray() should return array('foo' => string, 'fizz' => string) but returns array.
+19: Method ConfigWrapper::toArray() should return array{foo: string, fizz: string} but returns array. Full report
|
@eigan After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $array of function bar expects array('bar' => string), array given.
+10: Parameter #1 $array of function bar expects array{bar: string}, non-empty-array given. Full report
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+64: Method ArrayItemRemoval::getResultSettings() should return array{remove: string, limit: int} but returns non-empty-array<string, mixed>.
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit is never read, only written. Full report
|
@BackEndTea After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+28: Method ArrayItemRemoval::getResultSettings() should return array{remove: string, limit: int} but returns non-empty-array<string, mixed>.
+17: Method ArrayItemRemoval::getResultSettings() is unused. Full report
|
@bbatsche After the latest commit in dev-master, PHPStan now reports different result with your code snippet: @@ @@
-19: Method ConfigWrapper::toArray() should return array('foo' => string, 'fizz' => string) but returns array.
+19: Method ConfigWrapper::toArray() should return array{foo: string, fizz: string} but returns non-empty-array<'fizz'|'foo', string>. Full report
|
@BackEndTea After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-64: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+25: Property ArrayItemRemoval::$remove is never read, only written.
+30: Property ArrayItemRemoval::$limit is never read, only written. Full report
|
@BackEndTea After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-28: Method ArrayItemRemoval::getResultSettings() should return array('remove' => string, 'limit' => int) but returns array<string, mixed>.
+17: Method ArrayItemRemoval::getResultSettings() is unused. Full report
|
@eigan After the latest push in 1.8.x, PHPStan now reports different result with your code snippet: @@ @@
-10: Parameter #1 $array of function bar expects array('bar' => string), array given.
+No errors |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug report
Code snippet that reproduces the problem
https://phpstan.org/r/db3495e0-2cc4-4acb-ba04-ce742258680a
A smaller variant of the original snippet:
https://phpstan.org/r/e2636992-cccb-46db-9f06-56a4e34c0855
Output:
Expected output
I would expect no issue, as within the method i make sure the two keys are the correct value.
The array merge makes sure the keys exist are there. Since it is a const the keys are (should) be known to phpstan. The rest of the method asserts they are correct.
I would've expected phpstan to add the new information of the shape of the array to the type system.
The text was updated successfully, but these errors were encountered: