-
Notifications
You must be signed in to change notification settings - Fork 539
Report float and null offset based on PHP version #4406
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
Report float and null offset based on PHP version #4406
Conversation
6b9f23d
to
cd4e33c
Compare
cd4e33c
to
456c943
Compare
This pull request has been marked as ready for review. |
namespace InvalidKeyArrayDimFetch; | ||
|
||
$a = []; | ||
$foo = $a[null]; |
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 moved PHP-related errors to the end for an easier handling in tests.
$a[true]; | ||
$a[false]; | ||
|
||
/** @var string|null $stringOrNull */ |
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 changed for a valid union here and move the invalid string|null to the end
BaselineNeonErrorFormatterIntegrationTest::testErrorWithTrait failure seems unrelated and doesn't fail locally. |
{ | ||
|
||
public static function getType(): Type | ||
public static function getType(?PhpVersion $phpVersion = null): Type |
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.
Why optional and nullable?
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.
It's used in ArrayType and ConstantArrayType
phpstan-src/src/Type/ArrayType.php
Line 273 in 2548dbb
$allowedArrayKeys = AllowedArrayKeysTypes::getType(); |
and I don't have a PHPVersion here
|
||
public function __construct( | ||
private RuleLevelHelper $ruleLevelHelper, | ||
private PhpVersion $phpVersion, |
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.
More modern approach is to get PhpVersions from Scope (a separate class).
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.
Does it means that all the method from PhpVersion should be deprecated/moved into PhpVersions ?
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.
Not yet
Thank you! |
Closes phpstan/phpstan#13592
We will still need an option to report array key cast, especially for boolean keys.
Partially solves phpstan/phpstan#7864