Conditions | 5 |
Paths | 5 |
Total Lines | 27 |
Lines | 22 |
Ratio | 81.48 % |
Tests | 13 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
25 | 7 | public function parse($payload) |
|
26 | { |
||
27 | 7 | View Code Duplication | if (function_exists('msgpack_unpack')) { |
|
|||
28 | 6 | if ($payload) { |
|
29 | 4 | $prevHandler = set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) { |
|
30 | throw new \Exception($errstr); // @codeCoverageIgnore |
||
31 | 4 | }); |
|
32 | |||
33 | try { |
||
34 | 4 | $msg = msgpack_unpack(trim($payload)); |
|
35 | 2 | if ( ! $msg) { |
|
36 | throw new \Exception('Unknown error'); // @codeCoverageIgnore |
||
37 | } |
||
38 | 4 | } catch (\Exception $e) { |
|
39 | 2 | set_error_handler($prevHandler); |
|
40 | 2 | throw new ParserException('Failed To Parse MSGPack - ' . $e->getMessage()); |
|
41 | } |
||
42 | |||
43 | 2 | set_error_handler($prevHandler); |
|
44 | |||
45 | 2 | return $msg; |
|
46 | } |
||
47 | 2 | return []; |
|
48 | } |
||
49 | |||
50 | throw new ParserException('Failed To Parse MSGPack - Supporting Library Not Available'); // @codeCoverageIgnore |
||
51 | } |
||
52 | } |
||
53 |
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.