collection-crud/src/ValueObject/Money.php

25 lines
461 B
PHP
Raw Normal View History

2022-03-03 10:53:48 -05:00
<?php declare(strict_types=1);
namespace App\ValueObject;
use Stringable;
2023-07-21 10:35:15 -04:00
class Money implements Stringable {
private readonly float $value;
2023-07-21 10:35:15 -04:00
public function __construct(mixed $value)
{
$this->value = (float) str_replace(['$', ','], '', (string) $value);
}
2023-07-21 10:35:15 -04:00
public function __toString(): string
{
return (string) $this->getValue();
}
2022-03-03 10:53:48 -05:00
2023-07-21 10:35:15 -04:00
public function getValue(): float
{
return (float) str_replace(['$', ','], '', (string) $this->value);
}
}