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

Function parse_attributes_array

src/parser/classes.rs:563–599  ·  view source on GitHub ↗

Parse key-value pairs from a PHP `$attributes` array literal and infer types from the default values. Accepts text starting with `[` and extracts `'key' => value` pairs where `value` is a PHP literal (`true`, `false`, `null`, integer, float, or string). Returns a list of `(column_name, php_type)` pairs.

(text: &str)

Source from the content-addressed store, hash-verified

561///
562/// Returns a list of `(column_name, php_type)` pairs.
563fn parse_attributes_array(text: &str) -> Vec<(String, PhpType)> {
564 let mut results = Vec::new();
565 let trimmed = text.trim();
566
567 let inner = if let Some(s) = trimmed.strip_prefix('[') {
568 s.strip_suffix(']').unwrap_or(s)
569 } else {
570 return results;
571 };
572
573 for segment in inner.split(',') {
574 let segment = segment.trim();
575 if segment.is_empty() {
576 continue;
577 }
578
579 let Some(arrow_pos) = segment.find("=>") else {
580 continue;
581 };
582
583 let key_part = segment[..arrow_pos].trim();
584 let value_part = segment[arrow_pos + 2..].trim();
585
586 let Some(key) = extract_string_literal(key_part) else {
587 continue;
588 };
589 if key.is_empty() {
590 continue;
591 }
592
593 if let Some(php_type) = crate::util::infer_type_from_literal(value_part) {
594 results.push((key, php_type));
595 }
596 }
597
598 results
599}
600
601/// Extract timestamp configuration from a model class.
602///

Callers 1

Calls 5

pushMethod · 0.80
extract_string_literalFunction · 0.70
infer_type_from_literalFunction · 0.50
is_emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected