-
Notifications
You must be signed in to change notification settings - Fork 215
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
Closes #6833: Refactor to comply with phpstan level 4 #6971
Conversation
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more Footnotes
|
ea83d55
to
c950dad
Compare
3e28b64
to
33523cd
Compare
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.
Relating Tests results below:
Uploading testrail-report-639.pdf…
Description
This PR cover the level 4 of PHPStan. As I've put everything in a single commit, this could look overwhelming. However, here is a quick overview of errors PHPStan was giving:
1. Unused Methods/Properties
These errors highlight methods or properties defined in tests but never used. They might indicate dead code or functionality that was added but not utilized, possibly leftovers from refactoring or incomplete test cases.
2. Unreachable Code
PHPStan detects sections of code that can never be executed due to conditions or logic that always result in termination (e.g., return statements or exceptions). These often point to redundant code or improper flow control.
3. Boolean Logic Issues
Certain boolean expressions are flagged because they always resolve to the same outcome. This suggests logic errors, often due to overly simplistic conditions or unnecessary negations that don’t change the result.
4. Assertions that Always Evaluate to True/False
Some test assertions will always pass or fail because their conditions are inherently true or false. This reduces the usefulness of the test, indicating they need refinement or their logic adjusted for meaningful validation.
5. PHPDoc-Related Type Mismatches
PHPStan finds discrepancies between types declared in PHPDoc comments and the actual types used in the code, particularly in method calls. This could mean incorrect assumptions in documentation, which may lead to confusion or improper type handling during execution.
Fixes #6833
It doesn't impact user.
Type of change
Detailed scenario
No scenario.
Technical description
Documentation
1. Unused Methods/Properties
Methods & Properties that were never used have been deleted if it was okay in the process of WP Rocket.
2. Unreachable Code
Some code were unreachable due to two main reason:
a. Some functions are stopping the execution of PHP (
$this->markTestSkipped()
,wp_error_json()
), and we had code afterwards. In this case, as it's breaking tests if we are removing the code, a ignore line has been added.b. Sometimes, we are returning a value, while having other function call after. In this case, this code has been removed.
3. Boolean Logic Issues
Most of the time, this is due to over-safeguarding. To avoid that, I've added typed parameters in functions and also replaced the use of
apply_filters
bywpm_apply_filters_typed()
.4. Assertions that Always Evaluate to True/False
This happens in tests, where we have
$this->assertTrue(true);
. In this case a ignore line has been added to avoid the test to be flag without assertion.5. PHPDoc-Related Type Mismatches
PhpDocumentation has been updated to reflect the truth about some function return type, and parameters as it's been modified overtime, without a change in the phpdoc, misleading PHPStan.
New dependencies
N/A
Risks
N/A
Mandatory Checklist
Code validation
Code style
Additional Checks