We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
21 | class ErrorHandlerTest extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | /** @var ErrorHandler */ |
||
24 | private $errorHandler; |
||
25 | |||
26 | public function setUp() |
||
30 | |||
31 | public function testMaskErrorWithThrowExceptionSetToFalse() |
||
32 | { |
||
33 | $executionResult = new ExecutionResult( |
||
34 | null, |
||
35 | [ |
||
36 | new Error('Error without wrapped exception'), |
||
37 | new Error('Error with wrapped exception', null, new \Exception('My Exception message')), |
||
38 | new Error('Error with wrapped user error', null, new UserError('My User Error')), |
||
39 | new Error('', null, new UserErrors(['My User Error 1', 'My User Error 2', new UserError('My User Error 3')])), |
||
40 | new Error('Error with wrapped user warning', null, new UserWarning('My User Warning')), |
||
41 | ] |
||
42 | ); |
||
43 | |||
44 | $this->errorHandler->handleErrors($executionResult); |
||
45 | |||
46 | $expected = [ |
||
47 | 'data' => null, |
||
48 | 'errors' => [ |
||
49 | [ |
||
50 | 'message' => 'Error without wrapped exception', |
||
51 | ], |
||
52 | [ |
||
53 | 'message' => ErrorHandler::DEFAULT_ERROR_MESSAGE, |
||
54 | ], |
||
55 | [ |
||
56 | 'message' => 'Error with wrapped user error', |
||
57 | ], |
||
58 | [ |
||
59 | 'message' => 'My User Error 1', |
||
60 | ], |
||
61 | [ |
||
62 | 'message' => 'My User Error 2', |
||
63 | ], |
||
64 | [ |
||
65 | 'message' => 'My User Error 3', |
||
66 | ], |
||
67 | ], |
||
68 | 'extensions' => [ |
||
69 | 'warnings' => [ |
||
70 | [ |
||
71 | 'message' => 'Error with wrapped user warning', |
||
72 | ], |
||
73 | ], |
||
74 | ], |
||
75 | ]; |
||
76 | |||
77 | $this->assertEquals($expected, $executionResult->toArray()); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @expectedException \Exception |
||
82 | * @expectedExceptionMessage My Exception message |
||
83 | */ |
||
84 | public function testMaskErrorWithWrappedExceptionAndThrowExceptionSetToTrue() |
||
95 | |||
96 | View Code Duplication | public function testMaskErrorWithWrappedUserErrorAndThrowExceptionSetToTrue() |
|
118 | |||
119 | View Code Duplication | public function testMaskErrorWithoutWrappedExceptionAndThrowExceptionSetToTrue() |
|
141 | |||
142 | public function testConvertExceptionToUserWarning() |
||
168 | } |
||
169 |
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.