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 |
||
17 | final class MongoLoggerTest extends TestCase |
||
18 | { |
||
19 | /** |
||
20 | * Verify basic behavior of log(). |
||
21 | * |
||
22 | * @test |
||
23 | * @covers ::log |
||
24 | * |
||
25 | * @return void |
||
26 | */ |
||
27 | public function log() |
||
41 | |||
42 | /** |
||
43 | * Verify behavior of log() with message interpolation. |
||
44 | * |
||
45 | * @test |
||
46 | * @covers ::log |
||
47 | * |
||
48 | * @return void |
||
49 | */ |
||
50 | View Code Duplication | public function logWithInterpolation() |
|
60 | |||
61 | /** |
||
62 | * Verify behavior of log() when $level is not known. |
||
63 | * |
||
64 | * @test |
||
65 | * @covers ::log |
||
66 | * @expectedException \Psr\Log\InvalidArgumentException |
||
67 | * @expectedExceptionMessage Given $level was not a known LogLevel |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | public function logUnknownLevel() |
||
77 | |||
78 | /** |
||
79 | * Verify behavior of log() when $message is not a valid string value. |
||
80 | * |
||
81 | * @test |
||
82 | * @covers ::log |
||
83 | * @expectedException \Psr\Log\InvalidArgumentException |
||
84 | * @expectedExceptionMessage Given $message was a valid string value |
||
85 | * |
||
86 | * @return void |
||
87 | */ |
||
88 | public function logNonStringMessage() |
||
94 | |||
95 | /** |
||
96 | * Verify behavior of log() when $message is an object with __toString(). |
||
97 | * |
||
98 | * @test |
||
99 | * @covers ::log |
||
100 | * |
||
101 | * @return void |
||
102 | */ |
||
103 | View Code Duplication | public function logObjectMessage() |
|
117 | |||
118 | /** |
||
119 | * Verify context is normalized when log(). |
||
120 | * |
||
121 | * @test |
||
122 | * @covers ::log |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | public function logNormalizesContext() |
||
148 | |||
149 | /** |
||
150 | * Verify exception is handled properly. |
||
151 | * |
||
152 | * @test |
||
153 | * @covers ::log |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | public function logWithException() |
||
183 | |||
184 | private function getMongoCollectionMockWithAsserts($level, $message, $extra, $exception) |
||
206 | } |
||
207 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: