Conversation
|
@Ocramius I've re-added the |
0bc8963 to
d638959
Compare
|
👋 Hello! I've spent some time on this branch, and here's my current thinking, along with an approach.
I'm planning on working through the error list this morning, but wanted to drop this into the PR thread to make sure that folks were on board with this approach before getting too far into it. |
Coming from #603, this is an attempt to fix the errors raised by the current phpstan settings. I went through each of the errors raised by phpstan with the following approach. - If a method is part of an `@immutable` class, we can consider it pure, assuming it only affects internal variables. - If a potentially pure method is calling a class's method that is only swapped during testing (and not during normal usage), then we can consider the calling method pure. - If a class is marked deprecated, don't bother with attempting to mark it pure or immutable.
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## 4.x #603 +/- ##
============================================
+ Coverage 95.06% 95.11% +0.04%
Complexity 574 574
============================================
Files 70 70
Lines 1622 1637 +15
============================================
+ Hits 1542 1557 +15
Misses 80 80
|
These were removed in 691c2c8 but should remain in the code base.
Coming from #603, this is an attempt to fix the errors raised by the current phpstan settings. I went through each of the errors raised by phpstan with the following approach. - If a method is part of an `@immutable` class, we can consider it pure, assuming it only affects internal variables. - If a potentially pure method is calling a class's method that is only swapped during testing (and not during normal usage), then we can consider the calling method pure. - If a class is marked deprecated, don't bother with attempting to mark it pure or immutable.
147b960 to
198a34a
Compare
|
Thanks so much for your help, @fillerwriter! @Ocramius, I'd love for you to take a final glance at this before I merge it into the If it's considered new, backward-compatible functionality, then all is well, and I'll tag a 4.x.0 release. Otherwise, I want to remove the annotations that cause BC breaks for |
|
@fillerwriter, I addressed your concerns about the PHPStan errors in the tests here: 198a34a I'm still not sure why it only just now started complaining about that. |
|
Nice! Re: PHPStan errors in tests, that's a nice trick! I didn't know you could filter errors based on the folder. |
I didn't, either, but I suspected you could, so I figured that out tonight. 🙂 |
|
@ramsey fwiw, @fillerwriter's analysis is correct, and the suppressions correspond to my initial design too (which is also what highlighted the entire factory problematic under the hood) |
Ocramius
left a comment
There was a problem hiding this comment.
From my PoV, this patch reflects the initial design when @pure was introduce.
The only thing that is a bit annoying is the fact that we need to suppress inline so much, but on the other end, it was kinda expected.
LGTM
| { | ||
| public function encode(UuidInterface $uuid): string | ||
| { | ||
| /** @phpstan-ignore possiblyImpure.methodCall */ |
There was a problem hiding this comment.
Deep inside these implementations, I'd suggest suppressing the entire category of errors at class level, where needed
There was a problem hiding this comment.
I tried adding @phpstan-ignore at the method level, and it wouldn't work. PHPStan was telling me there wasn't a possiblyImpure.methodCall error on the next line. The only way I could find to squelch the errors is to inline them like this or add them to the config file, but I'd rather leave them in the code.
src/Codec/OrderedTimeCodec.php
Outdated
| /** @phpstan-ignore possiblyImpure.methodCall */ | ||
| !($uuid->getFields() instanceof Rfc4122FieldsInterface) | ||
| /** @phpstan-ignore possiblyImpure.methodCall */ | ||
| || $uuid->getFields()->getVersion() !== Uuid::UUID_TYPE_TIME |
There was a problem hiding this comment.
Interesting here: getFields() gets called twice, which is a small thing to optimize away, and reduces us to a single suppression
Coming from #603, this is an attempt to fix the errors raised by the current phpstan settings. I went through each of the errors raised by phpstan with the following approach. - If a method is part of an `@immutable` class, we can consider it pure, assuming it only affects internal variables. - If a potentially pure method is calling a class's method that is only swapped during testing (and not during normal usage), then we can consider the calling method pure. - If a class is marked deprecated, don't bother with attempting to mark it pure or immutable.
Description
Add
@pureannotations where the@psalm-pureannotations used to be.Motivation and context
These were removed in 691c2c8 but should remain in the code base.
For more information, see discussion at 691c2c8#r160296998
How has this been tested?
Static analysis is now failing on each@puremethod. I will need some help resolving the failures.Thanks to @fillerwriter (see #605), static analysis is now passing!
Types of changes
PR checklist