| Conditions | 6 |
| Paths | 9 |
| Total Lines | 32 |
| Code Lines | 17 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 56 | public function from($input) |
||
| 57 | { |
||
| 58 | if ($input === '0') { |
||
| 59 | return 0; |
||
| 60 | } |
||
| 61 | |||
| 62 | $res = $i = 0; |
||
| 63 | $len = strlen($input); |
||
| 64 | $sign = 1; |
||
| 65 | |||
| 66 | if (substr($input, 0, 1) === '-') { |
||
| 67 | $sign = -1; |
||
| 68 | $i = 1; |
||
| 69 | } |
||
| 70 | |||
| 71 | while ($i < $len) { |
||
| 72 | foreach (static::$table as $symbol => $value) { |
||
| 73 | $sl = strlen($symbol); |
||
| 74 | |||
| 75 | if ($symbol === substr($input, $i, $sl)) { |
||
| 76 | $res += $value; |
||
| 77 | $i += $sl; |
||
| 78 | |||
| 79 | continue 2; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | // If nothing matched, exit. |
||
| 84 | return null; |
||
| 85 | } |
||
| 86 | |||
| 87 | return $sign * $res; |
||
| 88 | } |
||
| 90 |