-
Notifications
You must be signed in to change notification settings - Fork 470
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
Add support for internal classes that overload offset access #3725
Add support for internal classes that overload offset access #3725
Conversation
Please add a regression test to NonexistentOffsetInArrayDimFetchRuleTest, thanks. |
1875d6c
to
bff963c
Compare
Tests added, and rebased to One set of tests are case which should fail, but currently cannot. |
@@ -0,0 +1,74 @@ | |||
<?php // lint >= 8.4 |
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 doesn't seem to be working? Not sure why however.
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 only works in /nsrt/
. But here you're in a rule test. Which means you need to call $this->markTestSkipped()
in the test based on PHP_VERSION_ID. There are many existing tests that do this.
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 only works in
/nsrt/
. But here you're in a rule test. Which means you need to call$this->markTestSkipped()
in the test based on PHP_VERSION_ID. There are many existing tests that do this.
Remember I tried to introduce a new annotation syntax that would allow us to use the same skip system for all data files? (main gotcha was data files that required ranges and additional conditions for skipping). The current system is cumbersome and unintuitive. Would you like to revisit my idea? I can provide a sample PR on which to discuss it.
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 current system works very well in my opinion :)
One day we might be able to test the rules in a similar way we test inferred types (by discovering and filtering files in a directory) but today is not that day.
@ondrejmirtes is there anything else I need to do? :) |
<?php | ||
/** | ||
* All of these offset accesses are invalid | ||
* ++ and -- are also disallowed in general are they operate "by ref" |
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.
* ++ and -- are also disallowed in general are they operate "by ref" | |
* ++ and -- are also disallowed in general as they operate "by ref" |
<?php | ||
/** | ||
* All of these offset accesses are invalid | ||
* ++ and -- are also disallowed in general are they operate "by ref" |
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.
* ++ and -- are also disallowed in general are they operate "by ref" | |
* ++ and -- are also disallowed in general as they operate "by ref" |
tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php
Outdated
Show resolved
Hide resolved
tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php
Outdated
Show resolved
Hide resolved
Thank you! |
Quick fix for phpstan/phpstan#12235 as
DOMNodeList
already doesn't complain about incorrect writes it makes sense to have the same behaviour for the other internal classes until PHPStan uses the access mode of the offset.