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)
| 497 | /// - `Address::class.':argument'` — strips the concatenated argument |
| 498 | /// suffix and returns `"Address"` |
| 499 | fn 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 | /// |
no test coverage detected