[Refactor:CourseMaterials] Phpstan 2.1.32 compatibility#12150
Conversation
…lderPathsR method
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #12150 +/- ##
=========================================
Coverage 21.69% 21.69%
Complexity 9618 9618
=========================================
Files 268 268
Lines 36113 36113
Branches 478 478
=========================================
Hits 7835 7835
Misses 27804 27804
Partials 474 474
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
| * | ||
| * @param array<mixed> $course_materials - Dictionary: path name => CourseMaterial. | ||
| * @param array<string> $folder_paths - List we append | ||
| * @param array<int|string, int|string> $folder_paths - List we append |
There was a problem hiding this comment.
Why do we need to allow integers in folder_paths?
And why are you changing it from a string array to a map?
| * @param array<mixed> $course_materials - Dictionary: path name => CourseMaterial. | ||
| * @return array<string> List of folders paths. | ||
| * @param array<string, CourseMaterial|array<string, CourseMaterial>> $course_materials - Dictionary: path name => CourseMaterial. | ||
| * @return array<int, string> List of folders paths. |
There was a problem hiding this comment.
| * @return array<int, string> List of folders paths. | |
| * @return array<string> List of folders paths. |
Is there a reason this was changed?
There was a problem hiding this comment.
compileAllFolderPaths returns $folder_paths, which is assigned by reference in compileAllFolderPathsR. In compileAllFolderPathsR, $folder_paths is assigned via invocation of array_push, which adds string elements (folder paths) to the array using int keys, which results in a sequential indexed array of strings (array<int, string>). This is the doc type expected by PHPStan, so that's why the change had to be made.
) ### Why is this Change Important & Necessary? <!-- Include any GitHub issue that is fixed/closed using "Fixes #<number>" or "Closes #<number>" syntax. Alternately write "Partially addresses #<number>" or "Related to #<number>" as appropriate. --> As a continuation of #12150, before merging #12260, it is necessary to ensure that all of the code is compatible with the new version of PHPStan. ### What is the New Behavior? <!-- Include before & after screenshots/videos if the user interface has changed. --> PHPStan 2.1.32 check now passes after this change. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Checkout #12260 and then PHPStan ([documentation](https://submitty.org/developer/testing/linting_static_analysis)) 2. Run `git diff main phpstan-upgrade-prep-2 | git apply` to apply the changes from this branch 3. Run PHPStan again and the test will pass --------- Co-authored-by: William Allen <william.j.allen24@gmail.com>
…mitty#12284) ### Why is this Change Important & Necessary? <!-- Include any GitHub issue that is fixed/closed using "Fixes #<number>" or "Closes #<number>" syntax. Alternately write "Partially addresses #<number>" or "Related to #<number>" as appropriate. --> As a continuation of Submitty#12150, before merging Submitty#12260, it is necessary to ensure that all of the code is compatible with the new version of PHPStan. ### What is the New Behavior? <!-- Include before & after screenshots/videos if the user interface has changed. --> PHPStan 2.1.32 check now passes after this change. ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Checkout Submitty#12260 and then PHPStan ([documentation](https://submitty.org/developer/testing/linting_static_analysis)) 2. Run `git diff main phpstan-upgrade-prep-2 | git apply` to apply the changes from this branch 3. Run PHPStan again and the test will pass --------- Co-authored-by: William Allen <william.j.allen24@gmail.com>
Why is this Change Important & Necessary?
Before we can merge #12093 (superseded by #12260), we need to make sure that all of our code is compatible with the new version of phpstan, and this was the one place that our code has started failing.
What is the New Behavior?
Phpstan 2.1.32 now passes after this change.
What steps should a reviewer take to reproduce or test the bug or new feature?
composer installand then phpstan and view that 1 error is detectedgit diff main phpstan-prep | git applyto get the changes from this branchAutomated Testing & Documentation
Other information