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

Function extract_deprecated_attribute

src/parser/mod.rs:484–536  ·  view source on GitHub ↗

Extract `#[Deprecated]` metadata from an element's attribute lists. Supports the syntactic forms found in phpstorm-stubs: - `#[Deprecated]` — bare, no arguments. - `#[Deprecated("reason text")]` — positional reason. - `#[Deprecated(reason: "...", since: "7.2")]` — named arguments. - `#[Deprecated("reason", replacement: "...", since: "7.2")]` — mixed. Attribute names are resolved through the [`D

(
    attribute_lists: &Sequence<'_, attribute::AttributeList<'_>>,
    ctx: &DocblockCtx<'_>,
)

Source from the content-addressed store, hash-verified

482///
483/// Returns `None` when no `#[Deprecated]` attribute is present.
484pub(crate) fn extract_deprecated_attribute(
485 attribute_lists: &Sequence<'_, attribute::AttributeList<'_>>,
486 ctx: &DocblockCtx<'_>,
487) -> Option<DeprecatedAttribute> {
488 for attr_list in attribute_lists.iter() {
489 for attr in attr_list.attributes.iter() {
490 if !is_known_deprecated_attr(&attr.name, ctx) {
491 continue;
492 }
493
494 // Bare #[Deprecated] — no argument list at all.
495 let Some(arg_list) = attr.argument_list.as_ref() else {
496 return Some(DeprecatedAttribute::default());
497 };
498
499 let mut reason: Option<String> = None;
500 let mut since: Option<String> = None;
501 let mut replacement: Option<String> = None;
502
503 for arg in arg_list.arguments.iter() {
504 match arg {
505 argument::Argument::Named(named) => {
506 let name = named.name.value.to_string();
507 let value = extract_string_literal_value(named.value, ctx.content);
508 match name.as_str() {
509 // JetBrains stubs use `reason:`, native PHP 8.4
510 // `\Deprecated` uses `message:`. Both mean the
511 // same thing — accept either.
512 "reason" | "message" => reason = value,
513 "since" => since = value,
514 "replacement" => replacement = value,
515 _ => {}
516 }
517 }
518 argument::Argument::Positional(positional) => {
519 // First positional argument is the reason/message.
520 if reason.is_none() {
521 reason = extract_string_literal_value(positional.value, ctx.content);
522 }
523 }
524 }
525 }
526
527 return Some(DeprecatedAttribute {
528 reason,
529 since,
530 replacement,
531 });
532 }
533 }
534
535 None
536}
537
538/// Check whether an attribute identifier refers to one of the known
539/// deprecation attributes (`\Deprecated` or `\JetBrains\PhpStorm\Deprecated`).

Callers 1

merge_deprecation_infoFunction · 0.85

Calls 4

is_known_deprecated_attrFunction · 0.85
iterMethod · 0.80
as_strMethod · 0.80

Tested by

no test coverage detected