| Conditions | 8 | 
| Paths | 9 | 
| Total Lines | 30 | 
| Code Lines | 18 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 14 | 
| CRAP Score | 8 | 
| Changes | 5 | ||
| Bugs | 0 | Features | 2 | 
| 1 | <?php | ||
| 25 | 9 | public function parse($payload) | |
| 26 |     { | ||
| 27 | 9 |         if (function_exists('MongoDB\BSON\toPHP') && ! function_exists('bson_decode')) { | |
| 28 | require_once(__DIR__ . '/BSONPolyfill.php'); //@codeCoverageIgnore | ||
| 29 | 9 |         } elseif ( ! (function_exists('bson_decode') || function_exists('MongoDB\BSON\toPHP'))) { | |
| 30 |             throw new ParserException('Failed To Parse BSON - Supporting Library Not Available');  // @codeCoverageIgnore | ||
| 31 | } | ||
| 32 | |||
| 33 | 9 |         if ($payload) { | |
| 34 | 6 |             $prevHandler = set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { | |
| 35 | throw new \Exception($errstr); // @codeCoverageIgnore | ||
| 36 | 6 | }); | |
| 37 | |||
| 38 |             try { | ||
| 39 | 6 | $bson = bson_decode(trim($payload, " \t\n\r\x0b")); // Don't trim \0, as it has valid meaning in BSON | |
| 40 | 3 |                 if ( ! $bson) { | |
| 41 |                     throw new \Exception('Unknown error');  // @codeCoverageIgnore | ||
| 42 | } | ||
| 43 | 6 |             } catch (\Exception $e) { | |
| 44 | 3 | set_error_handler($prevHandler); | |
| 45 | 3 |                 throw new ParserException('Failed To Parse BSON - ' . $e->getMessage()); | |
| 46 | } | ||
| 47 | |||
| 48 | 3 | set_error_handler($prevHandler); | |
| 49 | |||
| 50 | 3 | return $bson; | |
| 51 | } | ||
| 52 | |||
| 53 | 3 | return []; | |
| 54 | } | ||
| 55 | } | ||
| 56 | 
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.