Bump PHPStan to level 2 and fix all resulting issues#1196
Open
utkarshcloudinary wants to merge 2 commits into
Open
Bump PHPStan to level 2 and fix all resulting issues#1196utkarshcloudinary wants to merge 2 commits into
utkarshcloudinary wants to merge 2 commits into
Conversation
Raise the PHPStan analysis level from 1 to 2 and resolve the resulting issues that are safe, mechanical fixes: - Correct malformed PHPDoc tags (trailing periods, invalid array()/[] syntax, \array, $var ordering). - Use fully-qualified class names in PHPDoc where the containing namespace shadowed WP/global classes (WP_REST_*, Cloudinary\Connect). - Add an Elementor stub for the optional integration and register it. - Replace the removed Requests_Transport_cURL type hint with resource. - Narrow get_component()/managers[...] union return types at call sites so type-specific method/property access resolves. - Add \@property/@method annotations for magic __get/__call access (Settings, Setting, Relationship, Api). - Fix genuine argument-count/type bugs: save_value($media), drop ignored extra args to has_param()/get_settings(), cast numeric stats before arithmetic, correct WP_Post case, make Relationship::$post_id public. - Suppress one intentional dynamic WP_Post property write inline.
Repair genuine runtime bugs surfaced by PHPStan level 2 that referenced methods deleted in the earlier settings/UI decoupling refactor: - class-cache.php: the cache settings tabs called the removed Settings::create_setting() via a callback indirection that would fatal. Convert add_plugin/theme/wp/content_settings() to return their params and embed them inline in settings() (matching the working Assets pattern), and register the cache_point path hooks directly in setup_setting_tabs(). Remove the now-unused get_cache_settings(). - class-cache-status.php: box_status() built a table via the removed create_setting()/render_component(); rebuild it using the component part system so it renders correctly. - class-page.php + class-admin.php: notice() called the non-existent Setting::get_admin_notices(); route it through the Admin component and have get_admin_notices() return the renderable notice Setting built via init_components() (consistent with render_notices()). Also convert the inline union-narrowing @var hints added for the level bump to multi-line docblocks to satisfy WPCS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Approach
Raise the PHPStan analysis level from 1 to 2 and resolve all 88 resulting errors. Work is split into two commits:
1. Bump PHPStan to level 2 and fix type/annotation issues (81 issues, safe/mechanical)
array()/[]/\arraysyntax,@var $x Typeordering).Cloudinarynamespace shadowed WP/global classes (WP_REST_*,Cloudinary\Connect).phpstan.neon.dist.get_component()/managers[...]union return types at call sites so type-specific method/property access resolves.@property/@methodannotations for magic__get/__callaccess (Settings,Setting,Relationship,Api) — the szepeviktor/phpstan-wordpress extension enforces these.save_value($media), drop ignored extra args tohas_param()/get_settings(), cast numeric stats before arithmetic, correctWP_Postcase, makeRelationship::$post_idpublic.WP_Postproperty write inline.2. Fix broken references to removed settings API (7 issues, genuine pre-existing runtime bugs)
These referenced methods deleted in the earlier settings/UI decouple refactor (3c5cd8a, 2021-08-27) and would fatal if executed:
class-cache.php: the Site Cache tabs called the removedSettings::create_setting()via a callback indirection. Convertedadd_plugin/theme/wp/content_settings()to return their params and embedded them inline insettings()(matching the workingAssetspattern); thecache_pointpath hooks are now registered directly insetup_setting_tabs(). Removed the now-unusedget_cache_settings().class-cache-status.php:box_status()built a table via the removedcreate_setting()/render_component(); rebuilt using the component part system so it renders correctly.class-page.php+class-admin.php:notice()called the non-existentSetting::get_admin_notices(); routed through theAdmincomponent and hadget_admin_notices()return the renderable noticeSettingbuilt viainit_components()(consistent withrender_notices()).QA notes
[OK] No errors.composer lintmay OOM; scope to changed files with a raised limit):post_id.