Apply typed properties in classes/ via Rector. - #1982
Open
shadyvb wants to merge 2 commits into
Open
Conversation
shadyvb
marked this pull request as ready for review
September 2, 2026 09:56
Register TypedPropertyFromAssignsRector with extension-point base skips; hand-correct Plugin service holders and Connectors_Unit_Test Admin mock fidelity.
shadyvb
force-pushed
the
ticket/XWPENG-47-typed-props-classes
branch
from
September 2, 2026 10:12
e3fc25d to
47ed6f8
Compare
… contract (XWPENG-47). Guard the three wp_stream_settings_* filter boundaries in Settings so a misbehaving callback can never feed null or a non-array into properties that the typed-property Rector runs assign to directly: - get_option_key(): fall back to the computed key when the wp_stream_settings_option_key filter returns a non-string. - get_options(): fall back to the unfiltered options array when the wp_stream_settings_options filter returns a non-array. - get_fields(): keep the unfiltered fields when the wp_stream_settings_option_fields filter returns a non-array. These props are untyped today only because Rector skipped them due to the mixed filter assignments; any consumer with typed properties (or a future TypedPropertyFromAssigns run) would otherwise throw a TypeError on every request, since Settings is constructed on init. Also declare the DB_Driver::setup_storage() return type (Install) on the interface and the WPDB implementation. Plugin::$install is nullable-typed in this stack, so a custom wp_stream_db_driver driver returning anything else previously failed with a cryptic runtime TypeError; it now fails at class-load time inside the offending driver. Note: the setup_storage signature is technically breaking for third-party drivers that omit the return type.
14 tasks
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.
XWPENG-47 (sub-PR 2 of the typed-properties stack; base:
ticket/XWPENG-47-rector-config).Registers Rector
TypedPropertyFromAssignsRectorand applies it to theclasses/directory, converting untyped properties with@vardocblocks into native PHP 8.2 typed properties across 15 core classes (Plugin,Admin,Settings,Connectors,Install, etc.). Nullable types (?Admin,?List_Table,?array) are used where properties default tonull. Redundant@vardocblocks are removed where the type is expressed in the property declaration.rector.phpconfigures the rule withINLINE_PUBLIC => trueand skips extension-point base classes (Connector,Alert_Type,Alert_Trigger,Exporter) plus theconnectors/,alerts/, andexporters/directories so child classes are typed in later PRs (Q7 / T1.3).Follow-up hardening (commit 2):
Settingsfilter return values are guarded withis_string()/is_array()fallbacks so third-party filters returning unexpected types cannot triggerTypeErroron the newly typed$option_key,$fields, and$optionsproperties.DB_Driver::setup_storage()gains an: Installreturn type on the interface andDB_Driver_WPDBimplementation.Test adjustments: unit bootstrap defines
WP_STREAM_SETTINGS_CAPABILITY;Connectors_Unit_TestMockery mocks are typed asPlugin::class/Admin::classto satisfy typed property assignments.No runtime behavior changes under normal operation — this is a static-analysis and type-safety improvement only.
Commits
47ed6f88classes/via Rector.ea122a51Installreturn type toDB_Driver::setup_storage().Test plan
composer lintpass locallyChecklist
contributing.md).Release Changelog
Release Checklist
masterbranch.readme.txt.stream.php.Stable taginreadme.txt.classes/class-plugin.php.Change
[ ]to[x]to mark the items as done.