Extract Eloquent attribute defaults from a class's `$attributes` property. Scans the class members for a `$attributes` property with an array initializer (`protected $attributes = [...]`) and infers PHP types from the literal default values. Returns a list of `(column_name, php_type)` pairs. For example, `'role' => 'user'` produces `("role", "string")` and `'is_active' => true` produces `("is_a
(
members: impl Iterator<Item = &'a ClassLikeMember<'a>>,
content: &str,
)
| 527 | /// `'role' => 'user'` produces `("role", "string")` and |
| 528 | /// `'is_active' => true` produces `("is_active", "bool")`. |
| 529 | fn extract_attributes_definitions<'a>( |
| 530 | members: impl Iterator<Item = &'a ClassLikeMember<'a>>, |
| 531 | content: &str, |
| 532 | ) -> Vec<(String, PhpType)> { |
| 533 | for member in members { |
| 534 | if let ClassLikeMember::Property(Property::Plain(plain)) = member { |
| 535 | for item in plain.items.iter() { |
| 536 | let var_name = item.variable().name.to_string(); |
| 537 | let stripped = var_name.strip_prefix('$').unwrap_or(&var_name); |
| 538 | if stripped != "attributes" { |
| 539 | continue; |
| 540 | } |
| 541 | if let PropertyItem::Concrete(concrete) = item { |
| 542 | let span = concrete.value.span(); |
| 543 | let start = span.start.offset as usize; |
| 544 | let end = span.end.offset as usize; |
| 545 | if let Some(text) = content.get(start..end) { |
| 546 | return parse_attributes_array(text); |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | Vec::new() |
| 553 | } |
| 554 | |
| 555 | /// Parse key-value pairs from a PHP `$attributes` array literal and |
| 556 | /// infer types from the default values. |
no test coverage detected