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

Function is_stub_function_removed

src/stubs.rs:85–110  ·  view source on GitHub ↗

Quick byte-level check whether a stub function has been `@removed` at or before the given PHP version. This scans the raw PHP source for the function's docblock without a full AST parse, so it is cheap enough to call during completion filtering. Only the docblock immediately preceding `function ` is examined. Returns `true` when the function's docblock contains `@removed X.Y` and `p

(
    source: &str,
    func_name: &str,
    php_version: crate::types::PhpVersion,
)

Source from the content-addressed store, hash-verified

83/// Returns `true` when the function's docblock contains `@removed X.Y`
84/// and `php_version >= X.Y`.
85pub fn is_stub_function_removed(
86 source: &str,
87 func_name: &str,
88 php_version: crate::types::PhpVersion,
89) -> bool {
90 // Fast path: if the entire file doesn't contain `@removed`, no
91 // function in it can be version-gated. This skips ~92% of stub
92 // files without any allocations or string searches.
93 if !source.contains("@removed") {
94 return false;
95 }
96
97 // Use the short (unqualified) name for the search pattern.
98 let short = func_name.rsplit('\\').next().unwrap_or(func_name);
99
100 let needle = format!("function {short}(");
101 let Some(func_pos) = source.find(&needle).or_else(|| {
102 // Some stubs have a space or newline before `(`.
103 let needle2 = format!("function {short} ");
104 source.find(&needle2)
105 }) else {
106 return false;
107 };
108
109 is_preceding_docblock_removed(source, func_pos, php_version)
110}
111
112/// Quick byte-level check whether a stub class/interface/trait has been
113/// `@removed` at or before the given PHP version.

Callers 1

set_php_versionMethod · 0.85

Calls 4

containsMethod · 0.80
nextMethod · 0.80
findMethod · 0.45

Tested by

no test coverage detected