-
Notifications
You must be signed in to change notification settings - Fork 477
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
Mark DOMNamedNodeMap as taking a covariant DOMNode #3714
base: 1.12.x
Are you sure you want to change the base?
Conversation
7750ba6
to
b16dfce
Compare
Okay, I am seeing that the stubs are pulled from: https://github.com/phpstan/php-8-stubs, but how can I augment those? |
What bug are you trying to fix? With a phpstan.org/try sample I can direct you to the right test file. |
I've reduced some of my code to showcase the issue: https://phpstan.org/r/2ebd6b8b-17d6-47c3-b6e1-f1705c98460e I am trying to fix the undefined property access to |
So you can verify the "property not found" is no longer reported with a new test in: https://github.com/phpstan/phpstan-src/blob/2.0.x/tests/PHPStan/Rules/Properties/AccessPropertiesRuleTest.php I'd also add a new file in https://github.com/phpstan/phpstan-src/tree/2.0.x/tests/PHPStan/Analyser/nsrt which gets picked up by Also there should be a test that tests iterating over DOMNamedNodeMap gives the right type. Also when I check https://github.com/phpstan/php-8-stubs/blob/main/stubs/ext/dom/DOMNamedNodeMap.php the Thanks! :) |
I cannot get the tests to run, nor pass localy. Trying to run all of them uses I don't know how much memory, and I cannot run the |
@Girgias you can either run |
Right, (although needing to run 1050 tests at a time is somewhat suboptimal). But I still cannot get PHPStan to grab updated stubs as that is completely opaque. |
The fundamental issue seems to be that there is no way to overwrite the I'm happy to update the corresponding repo, but that doesn't seem like the best idea. I've submitted a PR to |
I've adjusted the tests a bit:
So now there are these failures in the /nsrt/ file:
|
ff44cf0
to
ca3e5d2
Compare
So now PHPStan is narrowing too much in |
The tests are only failing on PHP 8.1+ because thanks to phpstorm-stubs it's known the type cannot be null on 8.1+:
To have different assertions between PHP versions, you need to use For example array_column has different assertions for PHP 7, PHP 8, and PHP 8.2+. Seee |
Right, the php.net docs were leading me to believe it could be (aside: I updated my project to new DOM and phpstan complains a hella less as it is better organized and has more type info). |
btw @Girgias regarding test runs - I didn't want to be annoying by mentioning the obvious things, but you can always do something like the following to only run your test file and avoid having to wait for all the others and such: --- a/tests/PHPStan/Analyser/NodeScopeResolverTest.php
+++ b/tests/PHPStan/Analyser/NodeScopeResolverTest.php
@@ -25,6 +25,9 @@ class NodeScopeResolverTest extends TypeInferenceTestCase
*/
private static function findTestFiles(): iterable
{
+ yield __DIR__ . '/nsrt/DOMLegacyNamedNodeNap.php;
+ return;
+
foreach (self::findTestDataFilesFromDirectory(__DIR__ . '/nsrt') as $testFile) {
yield $testFile;
} at least that's how I work regularly, also when I step-debug through some type issues in a specific case and such. oh, and another thing - for a fix like this, if it would benefit users of PHPStan 1, it might be better to target the still supported 1.12.x branch in the end I suppose. But that's up to you and Ondřej in the end of course. |
Oh you should have, it's not because I work on PHP Core that I think of the obvious things to do. I don't mind backporting, if I'm explained the process, do I target the lower branch first and merge up or is it cherry-picking? But I still do not understand how PHPStan deals with stubs, the |
You mean the line PHPStan's stubs can only override PHPDocs. For native types, phpstorm-stubs and php-8-stubs are treated as the truth without possible workarounds. |
And regarding backporting: the lower branch is targeted (branch would need a rebase and 2.x commits removed), Ondřej regularly merges it up. |
096284d
to
578fc00
Compare
My PR on the PHPStorm stubs has landed, would it be better to just update those instead? |
I have a weekly workflow that updates phpstorm-stubs here. I just ran it early: #3733 So you can now update 2.0.x and see the effects of your changes there. And you can decide whether this PR is still relevant or not. Thanks. |
And indicate that
DOMNode::$attributes
is a node map ofDOMAttr
.Not sure how to write a test, nor if this is where I need to amend the stubs. But happy to be guided.