Skip to content
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

Merged
merged 7 commits into from
Dec 17, 2024

Conversation

Girgias
Copy link
Contributor

@Girgias Girgias commented Dec 11, 2024

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.

@ondrejmirtes
Copy link
Member

Please add a regression test to NonexistentOffsetInArrayDimFetchRuleTest, thanks.

@Girgias Girgias changed the base branch from 2.0.x to 1.12.x December 12, 2024 04:27
@Girgias Girgias force-pushed the easy-offset-access-fixes branch from 1875d6c to bff963c Compare December 12, 2024 04:27
@Girgias
Copy link
Contributor Author

Girgias commented Dec 12, 2024

Tests added, and rebased to 1.12.x.

One set of tests are case which should fail, but currently cannot.

@@ -0,0 +1,74 @@
<?php // lint >= 8.4
Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

@Girgias
Copy link
Contributor Author

Girgias commented Dec 17, 2024

@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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ++ 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* ++ and -- are also disallowed in general are they operate "by ref"
* ++ and -- are also disallowed in general as they operate "by ref"

@ondrejmirtes ondrejmirtes merged commit b66058f into phpstan:1.12.x Dec 17, 2024
16 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants