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 | final class ListMappingTest extends TestCase |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * @var SubjectClass |
||
26 | */ |
||
27 | private $mapping; |
||
28 | |||
29 | /** |
||
30 | * @var Column |
||
31 | */ |
||
32 | private $column; |
||
33 | |||
34 | /** |
||
35 | * @var MappingInterface |
||
36 | */ |
||
37 | private $entryMapping; |
||
38 | |||
39 | public function setUp() |
||
40 | { |
||
41 | $this->column = $this->createMock(Column::class); |
||
|
|||
42 | $this->entryMapping = $this->createMock(MappingInterface::class); |
||
43 | |||
44 | $this->mapping = new ListMapping($this->column, $this->entryMapping, "some origin"); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @test |
||
49 | */ |
||
50 | public function shouldHaveDBALColumn() |
||
51 | { |
||
52 | $this->assertSame($this->column, $this->mapping->getDBALColumn()); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @test |
||
57 | */ |
||
58 | public function shouldHaveEntryMapping() |
||
59 | { |
||
60 | $this->assertSame($this->entryMapping, $this->mapping->getEntryMapping()); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @test |
||
65 | */ |
||
66 | public function shouldHaveOrigin() |
||
67 | { |
||
68 | $this->assertSame("some origin", $this->mapping->describeOrigin()); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @test |
||
73 | */ |
||
74 | public function shouldCollectDBALColumns() |
||
75 | { |
||
76 | $this->assertSame([$this->column], $this->mapping->collectDBALColumns()); |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @test |
||
81 | */ |
||
82 | public function shouldResolveListValue() |
||
117 | |||
118 | /** |
||
119 | * @test |
||
120 | */ |
||
121 | public function shouldRevertListValue() |
||
156 | |||
157 | /** |
||
158 | * @test |
||
159 | */ |
||
160 | public function shouldRevertMultidimensionalListValue() |
||
161 | { |
||
193 | |||
194 | /** |
||
195 | * @test |
||
196 | */ |
||
197 | public function shouldAssertValue() |
||
205 | |||
206 | /** |
||
207 | * @test |
||
208 | */ |
||
209 | public function shouldThrowExceptionOnFailedAssertion() |
||
219 | |||
220 | /** |
||
221 | * @test |
||
222 | */ |
||
223 | View Code Duplication | public function shouldWakeUpInnerMapping() |
|
234 | |||
235 | } |
||
236 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..