-
Notifications
You must be signed in to change notification settings - Fork 126
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
Type declarations to increase phpstan to level 6 #591
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll 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. |
"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. |
@@ -160,7 +160,7 @@ public static function guessParameterNameByValue(string $value): string | |||
* | |||
* 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to define more precise array-key and value types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably - I will look in more detail when I get to do a lot a "real code".
@@ -48,8 +51,13 @@ public function testParseTz(): void | |||
END:VEVENT | |||
END:VCALENDAR'; | |||
|
|||
/** @var VCalendar<int, mixed> $vObject */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we define a more precise return-type instead?
Line 43 in 7c585e6
public static function read($data, int $options = 0, string $charset = 'UTF-8'): ?Document |
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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