Fix PHPCS and PHPStan issues across multiple files#818
Fix PHPCS and PHPStan issues across multiple files#818aslamdoctor wants to merge 11 commits intoWordPress:masterfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@aslamdoctor U2F.php and fido-u2f-admin you can ignore, we'll remove them in PR #439 completely. |
- Add PHPStan bootstrap file for runtime constants (TWO_FACTOR_DIR, TWO_FACTOR_VERSION) - Add missing properties ($new, $last_used) to Registration class - Fix PHPDoc types for show_two_factor_login, process_provider, authentication_page, rename_link, delete_link, and pack64 - Fix undefined variable bug in wp_ajax_inline_save - Add input validation, sanitization, and wp_unslash for $_POST/$_REQUEST usage - Remove redundant isset($user->ID) checks and always-true conditions - Cast base_convert() result to int for array offset usage
FIDO/U2F files will be removed entirely in PR WordPress#439, so changes to U2F.php and class-two-factor-fido-u2f-admin.php are unnecessary.
77084c1 to
19d592e
Compare
|
Whoops my stuff was outdated. That's what I get for being up and working early on a Sunday. |
|
Thanks for your reviews @georgestephanis. Always highly appreciated!! :) |
|
Can you mark them resolved? I didn't as I wanted to make sure all is ok. |
Tests pass false as $user to authentication methods. Replace the removed isset($user->ID) checks with explicit early return guards to safely handle this case without accessing properties on false.
Rename phpstan-bootstrap.php to constants.php and include it from two-factor.php so TWO_FACTOR_DIR and TWO_FACTOR_VERSION are defined in a single place.
- Define TWO_FACTOR_DIR and TWO_FACTOR_VERSION in two-factor.php before the ABSPATH check so PHPStan can discover them from scanned files - Remove constants.php to keep version strings in a single file - Bump PHPStan analysis level from 0 to 4 - Exclude FIDO/U2F files from PHPStan analysis - Add phpstan-ignore for Jetpack runtime compatibility check
There was a problem hiding this comment.
Pull request overview
This PR aims to eliminate PHPCS/PHPStan findings across the Two-Factor plugin by adjusting runtime constant initialization for static analysis, tightening PHPDoc types, and refining some provider logic/configuration.
Changes:
- Define
TWO_FACTOR_DIR/TWO_FACTOR_VERSIONintwo-factor.phpeven when WordPress isn’t loaded (to aid static analysis). - Update PHPDoc types and simplify some user guards/conditions in core and provider code.
- Adjust PHPStan configuration (including excluding several FIDO U2F provider files from analysis).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
two-factor.php |
Defines plugin constants before the ABSPATH guard to make them visible to static analysis. |
providers/class-two-factor-totp.php |
Removes a user-ID guard, tweaks whitespace, and casts base_convert() to (int) for array offsets. |
providers/class-two-factor-email.php |
Updates PHPDoc to WP_User|false and adds early returns when $user is falsy. |
class-two-factor-core.php |
Updates PHPDoc types and simplifies notice class construction. |
phpstan.dist.neon |
Excludes FIDO U2F provider files from PHPStan analysis. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
masteradhoc
left a comment
There was a problem hiding this comment.
adjusted the PR based on the copilot feedback. LGTM.
Summary
TWO_FACTOR_DIR,TWO_FACTOR_VERSION) unreachable during static analysis$new,$last_used) toRegistrationclass inincludes/Yubico/U2F.phpshow_two_factor_login,process_provider,authentication_page,rename_link,delete_link, andpack64wp_ajax_inline_savewhere a non-matching key could be incorrectly updatedsanitize_text_field), andwp_unslashfor$_POST/$_REQUESTusage inclass-two-factor-fido-u2f-admin.phpisset($user->ID)checks and always-true conditionsbase_convert()result to(int)for array offset usage inbase32_encode()Reference #437
Test plan
./vendor/bin/phpstan analyse --memory-limit=1G --no-progress— should pass with 0 errors at level 0phpstan.dist.neonand run analysis — should pass with 0 errorsphpstan.dist.neonand run analysis — should pass with 0 errors./vendor/bin/phpcs --standard=WordPress providers/class-two-factor-fido-u2f-admin.php— should pass with 0 errors/warnings