collection-crud/src/ValueObject/Money.php

26 lines
509 B
PHP
Raw Normal View History

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