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

Function extract_custom_collection

src/parser/classes.rs:305–326  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

303///
304/// The attribute takes priority because it is the newer Laravel API.
305fn 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.

Callers 1

Calls 5

nextMethod · 0.80
cloneMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected