| Total Complexity | 11 |
| Total Lines | 78 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class Roman implements NumberConverterInterface |
||
| 11 | { |
||
| 12 | protected static $table = [ |
||
| 13 | 'M' => 1000, |
||
| 14 | 'CM' => 900, |
||
| 15 | 'D' => 500, |
||
| 16 | 'CD' => 400, |
||
| 17 | 'C' => 100, |
||
| 18 | 'XC' => 90, |
||
| 19 | 'L' => 50, |
||
| 20 | 'XL' => 40, |
||
| 21 | 'X' => 10, |
||
| 22 | 'IX' => 9, |
||
| 23 | 'V' => 5, |
||
| 24 | 'IV' => 4, |
||
| 25 | 'I' => 1, |
||
| 26 | ]; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @inheritDoc |
||
| 30 | */ |
||
| 31 | public function to($input) |
||
| 32 | { |
||
| 33 | if ($input === 0) { |
||
| 34 | return '0'; |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($input < 0) { |
||
| 38 | return '-' . $this->to(-$input); |
||
| 39 | } |
||
| 40 | |||
| 41 | $res = ''; |
||
| 42 | |||
| 43 | foreach (self::$table as $symbol => $value) { |
||
| 44 | while ($input >= $value) { |
||
| 45 | $res .= $symbol; |
||
| 46 | $input -= $value; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return $res; |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @inheritDoc |
||
| 55 | */ |
||
| 56 | public function from($input) |
||
| 88 | } |
||
| 89 | } |
||
| 90 |