Check whether a resolved class name matches the target FQN. Two names match if their fully-qualified forms are equal, or if both are unqualified and their short names match.
(resolved: &str, target: &str, target_short: &str)
| 1596 | /// Two names match if their fully-qualified forms are equal, or if both |
| 1597 | /// are unqualified and their short names match. |
| 1598 | fn class_names_match(resolved: &str, target: &str, target_short: &str) -> bool { |
| 1599 | if resolved == target { |
| 1600 | return true; |
| 1601 | } |
| 1602 | // When neither name is qualified, compare short names. |
| 1603 | if !resolved.contains('\\') && !target.contains('\\') { |
| 1604 | return resolved == target_short; |
| 1605 | } |
| 1606 | // When the resolved name is unqualified but the target is |
| 1607 | // namespace-qualified, the resolved name might be a short-name |
| 1608 | // reference to the target class (e.g. `Request` referencing |
| 1609 | // `Illuminate\Http\Request` via a `use` import that was not |
| 1610 | // tracked in the resolved-names map). Accept the match only |
| 1611 | // when the short names agree. |
| 1612 | // |
| 1613 | // The reverse (resolved is qualified, target is unqualified) is |
| 1614 | // NOT accepted: `App\Helper` is a different class from a global |
| 1615 | // `Helper`, so matching by short name alone would produce false |
| 1616 | // positives. |
| 1617 | if !resolved.contains('\\') && target.contains('\\') { |
| 1618 | return resolved == target_short; |
| 1619 | } |
| 1620 | false |
| 1621 | } |
| 1622 | |
| 1623 | #[cfg(test)] |
| 1624 | mod tests; |
no test coverage detected