More PHPStan level 6 cleanups, enable level 6 by default - #1612
Conversation
| $sd = (array) $this; | ||
| [$style, $cell] = get_special_day_cell_parts($sd); |
There was a problem hiding this comment.
Slight preference for a bit more descriptive variable name.
| $sd = (array) $this; | |
| [$style, $cell] = get_special_day_cell_parts($sd); | |
| $sd_parts = (array) $this; | |
| [$style, $cell] = get_special_day_cell_parts($sd_parts); |
There was a problem hiding this comment.
Heh. Lazy developer! And actually this should be named $special_day_info -- it's an example of the TODO note in phpstan.neon where I say class SpecialDay and the SpecialDayInfo shaped array are sorta the same thing.
As a sidenote, it's kinda fascinating that you can convert an object to an associative array like this. I did it without really thinking about it, and when writing this reply, I suddenly doubted myself and wrote a little test to confirm that it works as you'd think -- properties get mapped to key/values. And yes, this is the documented behavior.
| level: 6 | ||
|
|
||
| ignoreErrors: | ||
| # TODO(bpfoley) PHPStan level 6 errors we haven't fixed yet |
There was a problem hiding this comment.
Let me know if you want help working through these files (assuming you are going to work on them -- you don't have to, obviously).
I'm happy to tackle some but will follow your lead since I don't know how many of them you've already started.
There was a problem hiding this comment.
Sure. Extra hands would be welcome. I haven't started yet, but I was going to work through all the .inc files first because often multiple pages depend on them, and then move on to the .php files which I'd imagine will be mostly standalone pieces of work.
I'll keep you posted on slack with what I'm doing, and I'll make sure not to build up much of a backlog. I think this is one of those cases where the timezone difference will work for us.
BTW I changed the ignore list in phpstan.neon so that the code we can fix all uses identifier/paths and the third party code uses message/paths.
Incuding a detailed array shape, which caught undocumented keys
4ef9b2b to
8de0184
Compare
This complains about missing function argument and return types, array key/value types, and iterator types. pinc/ is mostly level 6 clean. Add level 6 ignore warnings for third party code which we can't fix, and an explicit ignore list for the rest of the code that we can clean up over time.
This time, take some large and widely used associative arrays and define their array shapes as type aliases in
phpstan.neon.This allows us to cleanly identify the graph generation functions in
pinc/graph_data.inc, for example -- they're the functions that return aGraphConfig.Notes:
GraphConfigis most naturally represented as an array, as it exists to be serialized into a JSON string that's passed to the JavaScript plotting library. We could potentially make into a DTO, but then we'd need to write a custom JSON serialiser (using reflection) to ignore default fields, and I don't think it's worth it. Also config.data.y cannot easily be declared as(int|float)[]until we do a lot of cleanup elsewhere in the code.SpecialDayInfoshould perhaps be converted into a DTO. Also some of its functionality overlaps withclass SpecialDayintools/site_admin/manage_special_days.php. This ball of string should be disentangled, but that's another project.HeaderExtraArgscould also be a DTO.