Determine the custom collection class for an Eloquent model. Checks three sources in priority order: 1. `#[CollectedBy(CustomCollection::class)]` attribute on the class. 2. `/** @use HasCollection */` in `use_generics`. 3. A `newCollection()` method override whose return type names the custom collection class. The attribute takes priority because it is the newer Laravel API.
(
attribute_lists: &Sequence<'_, AttributeList<'_>>,
use_generics: &[(Atom, Vec<PhpType>)],
methods: &[MethodInfo],
content: &str,
)
| 303 | /// |
| 304 | /// The attribute takes priority because it is the newer Laravel API. |
| 305 | fn extract_custom_collection( |
| 306 | attribute_lists: &Sequence<'_, AttributeList<'_>>, |
| 307 | use_generics: &[(Atom, Vec<PhpType>)], |
| 308 | methods: &[MethodInfo], |
| 309 | content: &str, |
| 310 | ) -> Option<PhpType> { |
| 311 | // 1. Try the #[CollectedBy] attribute first. |
| 312 | if let Some(name) = extract_collected_by_attribute(attribute_lists, content) { |
| 313 | return Some(PhpType::Named(name)); |
| 314 | } |
| 315 | |
| 316 | // 2. Fall back to @use HasCollection<X>. |
| 317 | for (trait_name, args) in use_generics { |
| 318 | let short = trait_name.rsplit('\\').next().unwrap_or(trait_name); |
| 319 | if short == "HasCollection" && !args.is_empty() { |
| 320 | return Some(args[0].clone()); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | // 3. Fall back to newCollection() return type override. |
| 325 | extract_custom_collection_from_new_collection(methods) |
| 326 | } |
| 327 | |
| 328 | /// Extract the custom collection class from a `newCollection()` method |
| 329 | /// override. |
no test coverage detected