| Conditions | 6 | 
| Paths | 13 | 
| Total Lines | 32 | 
| Code Lines | 20 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 0 | 
| CRAP Score | 42 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php declare(strict_types=1);  | 
            ||
| 25 | public function format(Money $money): string  | 
            ||
| 26 |     { | 
            ||
| 27 | $currency = $money->getCurrency();  | 
            ||
| 28 |         if (!$this->currencies->contains($currency)) { | 
            ||
| 29 |             throw new FormatterException('Bitcoin formatter can only format Bitcoin currencies.'); | 
            ||
| 30 | }  | 
            ||
| 31 | |||
| 32 | $valueBase = $money->getAmount();  | 
            ||
| 33 | $negative = false;  | 
            ||
| 34 | |||
| 35 |         if ('-' === $valueBase[0]) { | 
            ||
| 36 | $negative = true;  | 
            ||
| 37 | $valueBase = substr($valueBase, 1);  | 
            ||
| 38 | }  | 
            ||
| 39 | |||
| 40 | $subunit = $this->currencies->subunitFor($currency);  | 
            ||
| 41 | $valueLength = strlen($valueBase);  | 
            ||
| 42 | |||
| 43 |         if ($valueLength > $subunit) { | 
            ||
| 44 | $formatted = substr($valueBase, 0, $valueLength - $subunit);  | 
            ||
| 45 |             if ($subunit) { | 
            ||
| 46 | $formatted .= '.';  | 
            ||
| 47 | $formatted .= substr($valueBase, $valueLength - $subunit);  | 
            ||
| 48 | }  | 
            ||
| 49 |         } else { | 
            ||
| 50 |             $formatted = '0.'.str_pad('', $subunit - $valueLength, '0').$valueBase; | 
            ||
| 51 | }  | 
            ||
| 52 | |||
| 53 | $formatted = BitcoinCurrencies::SYMBOL.$formatted;  | 
            ||
| 54 | $formatted = $negative === true ? '-'.$formatted : $formatted;  | 
            ||
| 55 | |||
| 56 | return $formatted;  | 
            ||
| 57 | }  | 
            ||
| 59 |