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,
)
| 789 | /// When `name` is a bare short name (no backslashes), the first class with |
| 790 | /// a matching `name` field is returned (preserving existing behavior). |
| 791 | pub(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: |
no test coverage detected