Skip to content

Commit

Permalink
Add parse capability.
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Apr 30, 2018
1 parent dbea047 commit d7d2245
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
"dev-master": "1.1-dev"
}
},
"minimum-stability": "dev"
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>

Expand Down
17 changes: 17 additions & 0 deletions src/MYR.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Money\MoneyFormatter;
use BadMethodCallException;
use Money\Currencies\ISOCurrencies;
use Money\Parser\DecimalMoneyParser;
use Money\Formatter\DecimalMoneyFormatter;

class MYR implements Contracts\Money, \JsonSerializable
Expand Down Expand Up @@ -49,6 +50,22 @@ public static function given($amount)
return static::withoutVat($amount);
}

/**
* Parse value as ringgit.
*
* @param string $amount
*
* @return static
*/
public static function parse(string $amount)
{
$parser = new DecimalMoneyParser(new ISOCurrencies());

return static::given(
$parser->parse($amount, 'MYR')->getAmount()
);
}

/**
* Returns the value represented by this object.
*
Expand Down
8 changes: 8 additions & 0 deletions tests/MYRTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public function it_can_be_initiated_using_given()
$this->assertSame('1000', $money->add($money)->getAmount());
}

/** @test */
public function it_can_be_initiated_using_parse()
{
$money = MYR::parse('2.50');

$this->assertSame('500', $money->add($money)->getAmount());
}

/** @test */
public function it_can_be_get_currency_information()
{
Expand Down

0 comments on commit d7d2245

Please sign in to comment.