| Conditions | 4 |
| Paths | 3 |
| Total Lines | 13 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 22 | public function parse($money, $forceCurrency = null) |
||
| 23 | { |
||
| 24 | if (is_string($money) === false) { |
||
|
|
|||
| 25 | throw new ParserException('Formatted raw money should be string, e.g. 100SAT'); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (!preg_match('/^(?<amount>-?\d+)\s?(?<currency>M?SAT)$/i', $money, $matches)) { |
||
| 29 | throw new ParserException('Value cannot be parsed to Satoshi.'); |
||
| 30 | } |
||
| 31 | |||
| 32 | $currency = $forceCurrency ?: new Currency(strtoupper($matches['currency'])); |
||
| 33 | |||
| 34 | return new Money($matches['amount'], $currency); |
||
| 35 | } |
||
| 37 |