2022-03-03 10:53:48 -05:00
|
|
|
<?php declare(strict_types=1);
|
2017-11-22 13:51:04 -05:00
|
|
|
|
2018-02-14 16:42:39 -05:00
|
|
|
namespace App\ValueObject;
|
2017-11-22 13:51:04 -05:00
|
|
|
|
2022-02-17 15:48:16 -05:00
|
|
|
use Stringable;
|
2017-11-22 13:51:04 -05:00
|
|
|
|
2022-03-03 10:53:48 -05:00
|
|
|
class Money implements Stringable
|
|
|
|
{
|
|
|
|
private readonly float $value;
|
2017-11-22 13:51:04 -05:00
|
|
|
|
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
|
|
|
}
|
2017-11-22 13:51:04 -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();
|
|
|
|
}
|
2018-02-14 16:42:39 -05:00
|
|
|
}
|