Skip to content

[Feature Request]: Support fetchClass resolved from a sibling parameter's literal value #1377

Description

@imaliouris

Feature Description

Description

Currently, classFields completion's fetchClass option supports three modes: "current" (the callee class), "containingClassField:fieldName" (a property on the containing class), and a fixed "classFqn" string. All three resolve the target class from the call site's structure or a static value — none of them can resolve the class from another parameter's literal value passed in the same call.

This makes it impossible to get correct autocomplete for a common pattern: a generic helper function that takes a class FQN as one argument and a property name of that class as another, e.g.:

toSnakeCase(ThemeSettings::class, 'helpScoutSupportBeaconId');
//                                  ^ would like this suggested based on ThemeSettings

Requested feature

A new fetchClass mode, e.g. "parameter:N", that resolves the target class from the literal value of parameter N in the same call — when that parameter is a ::class constant reference (similar to how class-string<T> is resolved by Psalm/PHPStan in a templated context).

Example ide.json usage

{
  "complete": "classFields",
  "options": {
    "fetchClass": "parameter:1",
    "fieldsFilter": { "fetch": "own", "modifier": ["public", "protected"] }
  },
  "condition": [
    { "functionNames": ["toSnakeCase"], "parameters": [2] }
  ]
}

Why this matters

Right now, the only workaround is restructuring the API so the class is the callee rather than an argument (e.g. ThemeSettings::toSnakeCase('...') via a shared trait), which works but forces an API shape change purely to satisfy IDE tooling. A fetchClass: "parameter:N" mode would let generic hydration/mapping/conversion helpers (a very common pattern — DTO mappers, snake_case/camelCase converters, attribute accessors) keep a natural fn($classFqn, $propertyName) signature while still getting correct, class-specific IDE suggestions.

I'd guess this is at minimum a moderate lift, since it likely requires resolving the literal ::class expression passed at each call site (not just a static config value) before the completion provider runs.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions