Skip to content

Bug: CurrencyField crasht op string-input (number_format type error) #143

Description

@ginkelsoft-development

Probleem

`src/Fields/Types/CurrencyField.php` regel 51 roept `number_format($value, ...)` aan zonder type-coercion. Bij waarden van type `string` (zoals "12.50" — wat normaal is uit databases met DECIMAL kolommen die als string terugkomen in PHP) crasht het met:

```
TypeError: number_format(): Argument #1 ($num) must be of type int|float, string given
```

Reproductie

```php
$field = CurrencyField::make('price');
$record = (object) ['price' => '12.50'];
$field->getDisplayValue($record); // TypeError
```

Impact

Crash bij weergave van currency-velden waar de raw DB-waarde een string is (alle DECIMAL kolommen op standaard PDO).

Fix

Cast defensief naar float:

```php
$value = $model->{$this->name} ?? null;
if ($value === null || $value === '') {
return '-';
}
$value = is_numeric($value) ? (float) $value : 0.0;
return number_format($value, ...);
```

Acceptatiecriteria

  • CurrencyField accepteert string, int, float, en null als value
  • Regression test in CurrencyFieldTest
  • Output bij null/'' is "-"
  • Niet-numerieke strings ("abc") leveren geen crash op

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions