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

Function is_known_deprecated_attr

src/parser/mod.rs:552–592  ·  view source on GitHub ↗

Check whether an attribute identifier refers to one of the known deprecation attributes (`\Deprecated` or `\JetBrains\PhpStorm\Deprecated`). The matching rules mirror PHP's attribute name resolution: - **Fully-qualified** (`\Deprecated`, `\JetBrains\PhpStorm\Deprecated`): strip the leading `\` and compare against [`DEPRECATED_FQNS`]. - **Qualified** (`JetBrains\PhpStorm\Deprecated`): resolve the

(name: &Identifier<'_>, ctx: &DocblockCtx<'_>)

Source from the content-addressed store, hash-verified

550/// name is in the current namespace. Only matches if the file is in the
551/// global namespace (i.e. the bare name equals a known FQN).
552fn is_known_deprecated_attr(name: &Identifier<'_>, ctx: &DocblockCtx<'_>) -> bool {
553 match name {
554 Identifier::FullyQualified(fq) => {
555 // Input boundary: AST fully-qualified names include the leading `\`.
556 let stripped = strip_fqn_prefix(fq.value);
557 DEPRECATED_FQNS.contains(&stripped)
558 }
559 Identifier::Qualified(q) => {
560 // Resolve the first segment via the use-map, then rebuild.
561 let first_seg = q.value.split('\\').next().unwrap_or(q.value);
562 if let Some(resolved_prefix) = ctx.use_map.get(first_seg) {
563 let rest = &q.value[first_seg.len()..]; // includes leading '\'
564 let fqn = format!("{}{}", resolved_prefix, rest);
565 DEPRECATED_FQNS.contains(&fqn.as_str())
566 } else {
567 // No use-map entry — prepend file namespace if present.
568 let fqn = if let Some(ns) = &ctx.namespace {
569 format!("{}\\{}", ns, q.value)
570 } else {
571 q.value.to_string()
572 };
573 DEPRECATED_FQNS.contains(&fqn.as_str())
574 }
575 }
576 Identifier::Local(local) => {
577 // Check use-map first (e.g. `use JetBrains\PhpStorm\Deprecated;`)
578 if let Some(fqn) = ctx.use_map.get(local.value) {
579 DEPRECATED_FQNS.contains(&fqn.as_str())
580 } else {
581 // No import — the name lives in the current namespace.
582 // Only matches if the file is in the global namespace.
583 let fqn = if let Some(ns) = &ctx.namespace {
584 format!("{}\\{}", ns, local.value)
585 } else {
586 local.value.to_string()
587 };
588 DEPRECATED_FQNS.contains(&fqn.as_str())
589 }
590 }
591 }
592}
593
594/// Extract the string value from a literal string expression by reading
595/// the source text between the expression's span and stripping quotes.

Callers 1

Calls 5

strip_fqn_prefixFunction · 0.85
containsMethod · 0.80
nextMethod · 0.80
as_strMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected