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

Function find_class_by_name

src/util.rs:791–805  ·  view source on GitHub ↗

Find a class in a slice by name, preferring namespace-aware matching when the name is fully qualified. When `name` contains backslashes (e.g. `Illuminate\Database\Eloquent\Builder`), the lookup checks each candidate's `file_namespace` field so that the correct class is returned even when multiple classes share the same short name but live in different namespace blocks within the same file (e.g. `

(
    all_classes: &'a [Arc<ClassInfo>],
    name: &str,
)

Source from the content-addressed store, hash-verified

789/// When `name` is a bare short name (no backslashes), the first class with
790/// a matching `name` field is returned (preserving existing behavior).
791pub(crate) fn find_class_by_name<'a>(
792 all_classes: &'a [Arc<ClassInfo>],
793 name: &str,
794) -> Option<&'a Arc<ClassInfo>> {
795 let short = short_name(name);
796
797 if name.contains('\\') {
798 let expected_ns = name.rsplit_once('\\').map(|(ns, _)| ns);
799 all_classes
800 .iter()
801 .find(|c| c.name == short && c.file_namespace.as_deref() == expected_ns)
802 } else {
803 all_classes.iter().find(|c| c.name == short)
804 }
805}
806
807/// Check whether `class` is a subtype of the class identified by
808/// `ancestor_name`. Returns `true` when:

Calls 5

containsMethod · 0.80
iterMethod · 0.80
short_nameFunction · 0.70
mapMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected