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

Function extract_collected_by_attribute

src/parser/classes.rs:270–293  ·  view source on GitHub ↗

Extract the custom collection class name from a `#[CollectedBy(X::class)]` attribute. Scans the class's attribute lists for an attribute whose short name is `CollectedBy` and extracts the first argument's text with `::class` stripped. Returns `None` if no such attribute exists.

(
    attribute_lists: &Sequence<'_, AttributeList<'_>>,
    content: &str,
)

Source from the content-addressed store, hash-verified

268/// `CollectedBy` and extracts the first argument's text with `::class` stripped.
269/// Returns `None` if no such attribute exists.
270fn extract_collected_by_attribute(
271 attribute_lists: &Sequence<'_, AttributeList<'_>>,
272 content: &str,
273) -> Option<String> {
274 for attr_list in attribute_lists.iter() {
275 for attr in attr_list.attributes.iter() {
276 let short = attr.name.last_segment();
277 if short != "CollectedBy" {
278 continue;
279 }
280 let arg_list = attr.argument_list.as_ref()?;
281 let first_arg = arg_list.arguments.first()?;
282 let span = first_arg.span();
283 let start = span.start.offset as usize;
284 let end = span.end.offset as usize;
285 let text = content.get(start..end)?;
286 let class_name = text.trim_end_matches("::class").trim();
287 if !class_name.is_empty() {
288 return Some(class_name.to_string());
289 }
290 }
291 }
292 None
293}
294
295/// Determine the custom collection class for an Eloquent model.
296///

Callers 1

Calls 4

iterMethod · 0.80
firstMethod · 0.45
getMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected