Skip to content

Commit

Permalink
Merge pull request #8 from yceruto/dto
Browse files Browse the repository at this point in the history
Improve MoneyDto to initialize null by default
  • Loading branch information
yceruto committed Jan 11, 2023
2 parents 8bed7b7 + 2c27100 commit 70722dc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Model/MoneyDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public static function fromCurrency(string $currency): self

public static function fromAmount(int|string $amount): self
{
return new self($amount);
return new self($amount, 'EUR');
}

public function __construct(
public int|string $amount = 0,
public string $currency = 'EUR',
public int|string|null $amount = null,
public ?string $currency = null,
) {
}

public function toMoney(): Money
{
assert('' !== $this->amount, 'Empty number is invalid');
assert(null !== $this->amount && '' !== $this->amount, 'Empty number is invalid');
assert(is_numeric($this->amount), 'Invalid digit a found');
assert('' !== $this->currency, 'Currency must be a non-empty-string value');
assert(null !== $this->currency && '' !== $this->currency, 'Currency must be a non-empty-string value');

return new Money($this->amount, new Currency($this->currency));
}
Expand Down

0 comments on commit 70722dc

Please sign in to comment.