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