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

Function build_interface_substitution_map

src/virtual_members/phpdoc.rs:881–909  ·  view source on GitHub ↗

Build a substitution map for mixin generic resolution by zipping the parent class's `@template` parameters with the type arguments provided Build a substitution map for a directly implemented interface. Maps the interface's template parameters to the concrete types provided in the class's `@implements` generics.

(
    class: &ClassInfo,
    iface: &ClassInfo,
)

Source from the content-addressed store, hash-verified

879/// Maps the interface's template parameters to the concrete types provided
880/// in the class's `@implements` generics.
881fn build_interface_substitution_map(
882 class: &ClassInfo,
883 iface: &ClassInfo,
884) -> HashMap<String, PhpType> {
885 if iface.template_params.is_empty() {
886 return HashMap::new();
887 }
888
889 let iface_short = short_name(&iface.name);
890
891 let type_args = class
892 .implements_generics
893 .iter()
894 .find(|(name, _)| short_name(name) == iface_short)
895 .map(|(_, args)| args);
896
897 let type_args = match type_args {
898 Some(args) => args,
899 None => return HashMap::new(),
900 };
901
902 let mut map = HashMap::new();
903 for (i, param_name) in iface.template_params.iter().enumerate() {
904 if let Some(arg) = type_args.get(i) {
905 map.insert(param_name.to_string(), arg.clone());
906 }
907 }
908 map
909}
910
911/// Build a substitution map for an interface's parent interface (interface extends).
912///

Callers 1

provideMethod · 0.85

Calls 8

iterMethod · 0.80
cloneMethod · 0.80
short_nameFunction · 0.50
is_emptyMethod · 0.45
mapMethod · 0.45
findMethod · 0.45
getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected