-
Notifications
You must be signed in to change notification settings - Fork 471
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
Remove incorrect doc leftover from 1.x #3732
Conversation
Yeah, sure, thanks :) |
On a side note I'm trying to update Bladestan to PHPStan 2.0, but I can't figure out how to not make use of if ($objectType instanceof ObjectType) {
if ($objectType->isInstanceOf(Component::class)->yes()) return true;
if ($objectType->isInstanceOf(Mailable::class)->yes()) return true;
if ($objectType->isInstanceOf(MailMessage::class)->yes()) return true;
} If I use If I instead create a new instance of P.s.s. PHPStan 2.0 has solved the performance issues we where having with Bladestan, so I'm very excited to get this out for everyone to use :) |
The proper way of asking about this is: $component = new ObjectType(Component::class);
if ($component->isSuperTypeOf($objectType)->yes()) return true; More about that here: https://phpstan.org/developing-extensions/type-system#querying-a-specific-type |
I also tried that, it also gives me a Here is the class being analyzed: https://github.com/TomasVotruba/bladestan/blob/main/tests/Rules/Fixture/laravel-mail_message-method.php and the code that I'm trying to update: https://github.com/TomasVotruba/bladestan/blob/8baf741ca5cf067c0fa5d1e94498ab7e8c5e9860/src/NodeAnalyzer/BladeViewMethodsMatcher.php#L124 |
There's a big difference between:
And
If you do the first approach and the class in $objectType extends/implements Component then the answer is yes() being true. |
You might need to create a union of those 3 classes and do the super type check with that I assume. Because, otherwise, PHPStan is correct, if you're only asking for Component, it could still be something else, which is the reason you end up with maybe. |
If you're not sure we can schedule a call and figure it out together. |
I did try
I don't think that's the issue here, but that could be an idea for simplifying the code.
I would appreciate that a lot :) In case someone want's to give it a go the offending code is covered by a unit test so you can test it by simply running phpunit for the project. PHPStan 2.0 support is found in the phpstan2 branch, it's fully working ... PHPStan is just less then happy with how things are implemented in a few places. |
I just checked out the project. Some tests are failing for me locally, all of it is about You're doing: $ruleError = RuleErrorBuilder::message($error->getMessage())
->file($phpFilePath)
->line($phpFileLine)
->metadata([
'template_file_path' => array_key_first($fileNameAndTemplateLine),
'template_line' => current($fileNameAndTemplateLine),
])
->build();
assert($ruleError instanceof IdentifierRuleError); But that doesn't make sense. You're supposed to call Here's more about that https://phpstan.org/blog/using-rule-error-builder |
You can get that from |
I'm working on the repo right now and I will send a PR once the code looks like it should and tests pass. |
Here you go: bladestan/bladestan#120 The main reason why some methods were returning |
Arh that makes a lot of sens I was feeling like it somehow just didn't recognize the classes when trying to rebuild the ObjectsType but only when it directly analyzed the code. Thank you so much for helping with this, I feel a lot better about releasing the next version now :D |
This appears to have come from a now removed function, or at least it doesn't really make sens to say to use accepts() instead of accepts() :)