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)
| 561 | /// |
| 562 | /// Returns a list of `(column_name, php_type)` pairs. |
| 563 | fn 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 | /// |
no test coverage detected