Skip to content

Commit

Permalink
Update money interop
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Aug 30, 2020
1 parent 009af82 commit 5c16dfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
18 changes: 9 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 6 additions & 14 deletions src/ValueObject/Bitcoin.php
Expand Up @@ -10,16 +10,18 @@

use Daikon\Interop\Assertion;
use Daikon\Interop\InvalidArgumentException;
use Daikon\Interop\MakeEmptyInterface;
use Daikon\Money\ValueObject\Money;
use NGUtech\Bitcoin\Service\SatoshiCurrencies;

final class Bitcoin extends Money implements MakeEmptyInterface
final class Bitcoin extends Money
{
/** @param string $value */
/** @param null|string $value */
public static function fromNative($value): self
{
Assertion::string($value, 'Must be a string.');
Assertion::nullOrString($value, 'Must be a string.');
if ($value === null) {
return new self;
}

if (!preg_match('/^(?<amount>-?\d+)\s?(?<currency>M?SAT|BTC|XBT)$/i', $value, $matches)) {
throw new InvalidArgumentException('Invalid amount.');
Expand All @@ -32,14 +34,4 @@ public static function zero($currency = null): self
{
return self::fromNative('0'.($currency ?? SatoshiCurrencies::MSAT));
}

public static function makeEmpty(): self
{
return self::zero();
}

public function isEmpty(): bool
{
return $this->isZero();
}
}

0 comments on commit 5c16dfe

Please sign in to comment.