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

Function extract_string_literal

src/parser/classes.rs:499–518  ·  view source on GitHub ↗

Extract the string content from a PHP string literal. Strips surrounding quotes (single or double) and returns the inner text. Returns `None` if the text is not a quoted string. Also handles: - `SomeCast::class` — returns `"SomeCast"` - `Address::class.':argument'` — strips the concatenated argument suffix and returns `"Address"`

(text: &str)

Source from the content-addressed store, hash-verified

497/// - `Address::class.':argument'` — strips the concatenated argument
498/// suffix and returns `"Address"`
499fn extract_string_literal(text: &str) -> Option<String> {
500 let t = text.trim();
501 if ((t.starts_with('\'') && t.ends_with('\'')) || (t.starts_with('"') && t.ends_with('"')))
502 && t.len() >= 2
503 {
504 return Some(t[1..t.len() - 1].to_string());
505 }
506 // For class-string cast values like `SomeCast::class` or
507 // `SomeCast::class.':argument'`, extract the class name.
508 // The concatenation dot may have surrounding whitespace, so
509 // look for `::class` and take everything before it.
510 if let Some(class_pos) = t.find("::class") {
511 let before = t[..class_pos].trim();
512 let name = strip_fqn_prefix(before);
513 if !name.is_empty() {
514 return Some(name.to_string());
515 }
516 }
517 None
518}
519
520/// Extract Eloquent attribute defaults from a class's `$attributes` property.
521///

Callers 4

parse_casts_arrayFunction · 0.70
parse_attributes_arrayFunction · 0.70
extract_timestamp_configFunction · 0.70
parse_string_listFunction · 0.70

Calls 3

strip_fqn_prefixFunction · 0.85
findMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected