Bump PHPStan to level 3 and fix all resulting issues#1198
Open
utkarshcloudinary wants to merge 1 commit into
Open
Bump PHPStan to level 3 and fix all resulting issues#1198utkarshcloudinary wants to merge 1 commit into
utkarshcloudinary wants to merge 1 commit into
Conversation
Raise the PHPStan analysis level from 2 to 3 and resolve the resulting issues, all safe PHPDoc/annotation corrections with no behavior change: - Correct return-type PHPDoc to match actual behavior: Assets:: generate_storage_signature (bool), Assets::build_item (array|null), Media::get_transformation (int|string|false), Media::cloudinary_url (string|null), Media::filter_downsize (array|false), Media:: get_context_options (string), Settings::save (string[]), Api::sign (string), Api::call (array|string|WP_Error), Page::form/notice and Sync::action (array|null), On_Off::sanitize_value (string). - Widen base Text::sanitize_value PHPDoc to mixed so the array/bool overrides (Checkbox, Cron, Crops, React, Tags_Input, On_Off) are covariant-compatible. - Fix settings/setting type confusion: correct Component\Settings interface param to Cloudinary\Settings, widen Settings_Component:: $settings and Delivery_Feature::$settings to Settings|Setting, align Gallery/Extensions/Global_Transformations settings property types. - Fix Setting::$parent (string slug, not self) and get_option_parent return (Setting|null). - Fix Sync::$managers to include Sync_Queue. - Fix Line_Stat $connect type (Cloudinary\Connect) and narrow at call site; allow numeric used_percent/limit. - Cast ini_get in Cron::$daemon_watcher_interval; default Api:: $pending_url to null; widen Url_Object::get_id to int|string|null. - Correct get_terms return-type PHPDoc and annotate video metadata to resolve offset access on WP stub arrays.
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 2 to 3 and resolve all 42 resulting errors. All fixes are safe PHPDoc/annotation corrections with no behavior change:
Return-type PHPDoc corrected to match actual behavior
Assets::generate_storage_signature→bool(returns a comparison result).Assets::build_item→array|null(early-returnsnullon empty input).Media::get_transformation→int|string|false(returns the found index orfalse).Media::cloudinary_url→string|null.Media::filter_downsize→array|false(short-circuits theimage_downsizefilter value).Media::get_context_options→string(returns animplode()d string).Settings::save→string[](collects pending slugs, only tested withempty()).Api::sign→string(returns asha1()),Api::call→array|string|WP_Error(can return the raw non-JSON body).Page::form/Page::notice/Sync::action→array|null.On_Off::sanitize_value→string(returns'on'/'some'/'off').Global_Transformations::get_terms→array<array{term: WP_Term, value: mixed}>, which also resolves the offset access on$item['term']at the call site.sanitize_valuecovarianceText::sanitize_valuePHPDoc tomixedso thearray/booloverrides (Checkbox,Cron,Crops,React,Tags_Input,On_Off) are covariant-compatible with the parent.Settings vs. Setting type confusion
Component\Settingsinterface param toCloudinary\Settings(implementations receive the coreSettings, not aSetting).Settings_Component::$settingsandDelivery_Feature::$settingstoSettings|Setting— subclasses narrow the property to a childSettingafter init (Extensions,Gallery,Responsive_Breakpoints).Gallery::$settings,Extensions::$settings, andGlobal_Transformations::$media_settingsPHPDoc with the objects actually assigned.Property/type fixes
Setting::$parentis a slugstring(set viaset_parent()), notself;Setting::get_option_parent()returnsSetting|null.Sync::$managersnow includesSync_Queue[].Line_Stat::$connecttyped asCloudinary\Connect(was shadowed by the UIConnectcomponent) and narrowed at the call site;$used_percent/$limitaccept the numeric valuesget_usage_stat()returns.ini_get()inCron::$daemon_watcher_interval; defaultApi::$pending_urltonull(wasarray()).Url_Object::get_id()toint|string|null(WordPress returns an int post id, Cloudinary returns a string public id).wp_get_attachment_metadata()results inVideoasarrayso thefileformatoffset resolves against the image-shaped WP stub.QA notes
[OK] No errors.composer lintmay OOM; scope to changed files with a raised limit):