| Conditions | 7 |
| Paths | 5 |
| Total Lines | 28 |
| Code Lines | 10 |
| Lines | 6 |
| Ratio | 21.43 % |
| 1 | <?php |
||
| 36 | public static function parse($str) { |
||
| 37 | // if string contains any of .eE just cast it to float |
||
| 38 | if (false !== strpbrk($str, '.eE')) { |
||
| 39 | return (float) $str; |
||
| 40 | } |
||
| 41 | |||
| 42 | // otherwise it's an integer notation that overflowed into a float |
||
| 43 | // if it starts with 0 it's one of the special integer notations |
||
| 44 | if ('0' === $str[0]) { |
||
| 45 | // hex |
||
| 46 | View Code Duplication | if ('x' === $str[1] || 'X' === $str[1]) { |
|
|
|
|||
| 47 | return hexdec($str); |
||
| 48 | } |
||
| 49 | |||
| 50 | // bin |
||
| 51 | View Code Duplication | if ('b' === $str[1] || 'B' === $str[1]) { |
|
| 52 | return bindec($str); |
||
| 53 | } |
||
| 54 | |||
| 55 | // oct |
||
| 56 | // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit (8 or 9) |
||
| 57 | // so that only the digits before that are used |
||
| 58 | return octdec(substr($str, 0, strcspn($str, '89'))); |
||
| 59 | } |
||
| 60 | |||
| 61 | // dec |
||
| 62 | return (float) $str; |
||
| 63 | } |
||
| 64 | } |
||
| 65 |
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.