Build a substitution map for a trait based on `@use` generics and the trait's `@template` parameters. If the using class declares `@use HasFactory ` and the trait `HasFactory` has `@template TFactory`, the returned map is `{TFactory => UserFactory}`.
(
trait_name: &str,
trait_info: &ClassInfo,
use_generics: &[(Atom, Vec<PhpType>)],
)
| 1092 | /// trait `HasFactory` has `@template TFactory`, the returned map is |
| 1093 | /// `{TFactory => UserFactory}`. |
| 1094 | fn build_trait_substitution_map( |
| 1095 | trait_name: &str, |
| 1096 | trait_info: &ClassInfo, |
| 1097 | use_generics: &[(Atom, Vec<PhpType>)], |
| 1098 | ) -> HashMap<String, PhpType> { |
| 1099 | if trait_info.template_params.is_empty() || use_generics.is_empty() { |
| 1100 | return HashMap::new(); |
| 1101 | } |
| 1102 | |
| 1103 | let trait_short = short_name(trait_name); |
| 1104 | |
| 1105 | // Find the @use entry that matches this trait. |
| 1106 | let type_args = use_generics |
| 1107 | .iter() |
| 1108 | .find(|(name, _)| { |
| 1109 | let name_short = short_name(name); |
| 1110 | name_short == trait_short |
| 1111 | }) |
| 1112 | .map(|(_, args)| args); |
| 1113 | |
| 1114 | let type_args = match type_args { |
| 1115 | Some(args) => args, |
| 1116 | None => return HashMap::new(), |
| 1117 | }; |
| 1118 | |
| 1119 | let mut map = HashMap::new(); |
| 1120 | for (i, param_name) in trait_info.template_params.iter().enumerate() { |
| 1121 | if let Some(arg) = type_args.get(i) { |
| 1122 | map.insert(param_name.to_string(), arg.clone()); |
| 1123 | } |
| 1124 | } |
| 1125 | map |
| 1126 | } |
| 1127 | |
| 1128 | /// Build a substitution map for a parent class based on the child's |
| 1129 | /// `@extends` generics and the parent's `@template` parameters. |
no test coverage detected