| Conditions | 7 |
| Paths | 5 |
| Total Lines | 25 |
| Code Lines | 10 |
| Lines | 6 |
| Ratio | 24 % |
| 1 | <?php |
||
| 36 | public static function parse($str) { |
||
| 37 | // handle plain 0 specially |
||
| 38 | if ('0' === $str) { |
||
| 39 | return 0; |
||
| 40 | } |
||
| 41 | |||
| 42 | // if first char is 0 (and number isn't 0) it's a special syntax |
||
| 43 | if ('0' === $str[0]) { |
||
| 44 | // hex |
||
| 45 | View Code Duplication | if ('x' === $str[1] || 'X' === $str[1]) { |
|
|
|
|||
| 46 | return hexdec($str); |
||
| 47 | } |
||
| 48 | |||
| 49 | // bin |
||
| 50 | View Code Duplication | if ('b' === $str[1] || 'B' === $str[1]) { |
|
| 51 | return bindec($str); |
||
| 52 | } |
||
| 53 | |||
| 54 | // oct (intval instead of octdec to get proper cutting behavior with malformed numbers) |
||
| 55 | return intval($str, 8); |
||
| 56 | } |
||
| 57 | |||
| 58 | // dec |
||
| 59 | return (int) $str; |
||
| 60 | } |
||
| 61 | } |
||
| 62 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.