Skip to content

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

Merged
Hug0-Drelon merged 5 commits into
masterfrom
feat/options-offset-inference
Oct 16, 2026
Merged

Hug0-Drelon merged 5 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
@Screenfeed
Screenfeed self-requested a review October 16, 2026 09:39
Comment thread src/OptionTypes.php Outdated
Comment thread src/OptionsOffsetExpressionTypeResolverExtension.php Outdated
Comment thread tests/OptionTypesRegistrySyncTest.php
The OptionTypes refactor dropped the non-empty-array intersection that
existed before; restore it so the inferred type matches the real shape.
Avoid resolving constant string types twice when inferring Options
offset and method return types.
@Hug0-Drelon
Hug0-Drelon merged commit bfaa65e into master Oct 16, 2026
0 of 2 checks passed
@Hug0-Drelon
Hug0-Drelon deleted the feat/options-offset-inference branch October 16, 2026 15:06
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().

2 participants