MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / enrich_single_parameter

Function enrich_single_parameter

src/inheritance.rs:268–288  ·  view source on GitHub ↗

Enrich a single child parameter from an ancestor parameter. Copies the ancestor's `type_hint` when the child lacks a docblock override, the ancestor has a richer type, **and** the child's native type is not a specific concrete type. PHP allows contravariant parameter types: a concrete class may declare `?int` where the interface says `int`, or Carbon's `setTimezone(DateTimeZone|string|int)` may

(existing_param: &mut ParameterInfo, ancestor_param: &ParameterInfo)

Source from the content-addressed store, hash-verified

266/// `@implements` tag substitutes the template to a concrete type),
267/// the ancestor's enriched type should flow through.
268fn enrich_single_parameter(existing_param: &mut ParameterInfo, ancestor_param: &ParameterInfo) {
269 // Type hint enrichment — the child must lack a docblock override
270 // AND the ancestor must have a richer type (docblock that goes
271 // beyond its native hint). Additionally, skip enrichment when
272 // the child has a specific native type (not `object`/`mixed`)
273 // because the child's declaration is intentional and may be
274 // wider than the ancestor's (contravariant parameters).
275 let child_has_specific_native = existing_param.native_type_hint.as_ref().is_some_and(|nt| {
276 !nt.is_object() && !nt.is_mixed() && !nt.is_array_like() && !nt.is_iterable()
277 });
278 if !child_has_specific_native
279 && lacks_docblock_override(&existing_param.type_hint, &existing_param.native_type_hint)
280 && ancestor_has_richer_type(&ancestor_param.type_hint, &ancestor_param.native_type_hint)
281 {
282 existing_param.type_hint = ancestor_param.type_hint.clone();
283 }
284 // Description enrichment
285 if existing_param.description.is_none() && ancestor_param.description.is_some() {
286 existing_param.description = ancestor_param.description.clone();
287 }
288}
289
290/// Enrich a child property with docblock information from an ancestor
291/// property.

Calls 7

lacks_docblock_overrideFunction · 0.85
ancestor_has_richer_typeFunction · 0.85
is_objectMethod · 0.80
is_mixedMethod · 0.80
is_array_likeMethod · 0.80
is_iterableMethod · 0.80
cloneMethod · 0.80

Tested by

no test coverage detected