Skip to content

feat(options): infer bracket access types for Options offsets - #27

Open
Hug0-Drelon wants to merge 3 commits into
masterfrom
feat/options-offset-inference
Open

Hug0-Drelon wants to merge 3 commits into
masterfrom
feat/options-offset-inference

Conversation

@Hug0-Drelon

@Hug0-Drelon Hug0-Drelon commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

What?

Add PHPStan inference for $options['key'] so bracket access matches ->get('key') for constant option keys on WP_Syntex\Polylang\Options\Options.

Why?

Polylang 3.7+ uses array syntax extensively ($options['version'], $this->options['default_lang']), but PHPStan resolves bracket access via ArrayAccess<non-falsy-string, mixed>, which forces mixed and dozens of inline @phpstan-var annotations in application code.

How?

  • Introduce OptionTypes as a single key → PHPStan type map (free + Pro keys).
  • Refactor OptionsGetDynamicMethodReturnTypeExtension to delegate to OptionTypes.
  • Add OptionsOffsetExpressionTypeResolverExtension for ArrayDimFetch on Options.
  • Add dedicated tests against real Polylang Options source (scanDirectories) plus Pro coverage via DI (proEnabled: true).

Test plan

  • composer test in polylang-phpstan (48 tests)
  • composer stan in polylang with synced extension (no errors on $this->options['default_lang'])

Unify option key typing in OptionTypes and add an expression resolver so
$options['key'] matches $options->get('key') when the offset is a constant.
Add registry sync tests, POLYLANG_PRO_PHPSTAN constant coverage, edge-case
assertions, README guidance, and fix the polylang scan path for local dev.
@Hug0-Drelon Hug0-Drelon self-assigned this Oct 9, 2026
@Hug0-Drelon Hug0-Drelon added the enhancement New feature or request label Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support dynamic return type for WP_Syntex\Polylang\Options\Abstract_Option::get().

1 participant