Skip to content

More PHPStan level 6 cleanups, enable level 6 by default - #1612

Merged
cpeel merged 4 commits into
DistributedProofreaders:masterfrom
bpfoley:ty-annotations
Aug 31, 2026
Merged

More PHPStan level 6 cleanups, enable level 6 by default#1612
cpeel merged 4 commits into
DistributedProofreaders:masterfrom
bpfoley:ty-annotations

Conversation

@bpfoley

@bpfoley bpfoley commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

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 a GraphConfig.

Notes:

  • GraphConfig is 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.
  • SpecialDayInfo should perhaps be converted into a DTO. Also some of its functionality overlaps with class SpecialDay in tools/site_admin/manage_special_days.php. This ball of string should be disentangled, but that's another project.
  • HeaderExtraArgs could also be a DTO.

Comment thread stats/pages_proofed_graphs.php
Comment on lines +217 to +218
$sd = (array) $this;
[$style, $cell] = get_special_day_cell_parts($sd);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight preference for a bit more descriptive variable name.

Suggested change
$sd = (array) $this;
[$style, $cell] = get_special_day_cell_parts($sd);
$sd_parts = (array) $this;
[$style, $cell] = get_special_day_cell_parts($sd_parts);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread phpstan.neon
level: 6

ignoreErrors:
# TODO(bpfoley) PHPStan level 6 errors we haven't fixed yet

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.
@cpeel
cpeel merged commit e868918 into DistributedProofreaders:master Aug 31, 2026
12 checks passed
@bpfoley
bpfoley deleted the ty-annotations branch August 31, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants