Type declarations to increase phpstan to level 6#591
Type declarations to increase phpstan to level 6#591phil-davis wants to merge 18 commits intosabre-io:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #591 +/- ##
============================================
- Coverage 98.76% 98.68% -0.08%
+ Complexity 1866 1865 -1
============================================
Files 71 71
Lines 5325 5329 +4
============================================
Hits 5259 5259
- Misses 66 70 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
"progress" report: phpstan [ERROR] Found 638 errors There were 880 errors, I have fixed 242 - that is 27.5% done! This is a painful job. |
| * This may be either a single, or multiple strings in an array. | ||
| * | ||
| * @param string|array $value | ||
| * @param int|string|array $value |
There was a problem hiding this comment.
is it possible to define more precise array-key and value types?
There was a problem hiding this comment.
probably - I will look in more detail when I get to do a lot a "real code".
| END:VEVENT | ||
| END:VCALENDAR'; | ||
|
|
||
| /** @var VCalendar<int, mixed> $vObject */ |
There was a problem hiding this comment.
can we define a more precise return-type instead?
Line 43 in 7c585e6
@var has the problem, that we need to declare it on every call-site
| $vcard->PHOTO = 'random_stuff'; | ||
| /* @phpstan-ignore-next-line 'Cannot call method add() on string' */ | ||
| $vcard->PHOTO->add(null, 'BASE64'); |
There was a problem hiding this comment.
how can we call ->add on a property, which we assigned a string shortly before?
is this related to magic __get & __set or similar, and we should/can use a extension in phpstan for that?
https://phpstan.org/developing-extensions/class-reflection-extensions
There was a problem hiding this comment.
yes, there is "magic property" stuff happening, so PHOTO does not really end up being a string!
I haven't dug deep into this. I was not being too concerned about the test code.
But I will probably have to dig into it when I get to the "real" code.
|
Types are declared in all test code. |
98b5190 to
c08a536
Compare
|
Note to interested people: I have had "other things" happening the last few months. This work here is volunteer work. Hopefully I will get enthusiastic about it again "real soon now" (tm) and have some time to put in. If anyone else wants to do this stuff, or help with it, feel free to ping me here and we can work out how to move forward. |
|
Rebased and resolved conflicts. Maybe I can get more work done on this "soon". |
phpstan reports: 588 Comparison operation "<" between int<1, max> and 1 is always false. That is correct. The code higher up sets $propertyCounters[$name] = 1; and then only ever increments it. So it can never be less than 1.
All of Component, Parameter and Property have 'name'. Moving it into Node helps phpstan to understand that 'name' always exists.
cbe2de8 to
18494f5
Compare
|
I rebased, resolved conflicts, applied the latest cs-fixer code-style changes. Now This looks like a big job. |
|
I tried to address some stuff here as well |
Bump dependencies in composer.json
Bump phpstan to level 6
WIP - fixup type declarations (test code)
ToDo - fixup type declarations (real code)
Towards issue #588