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 |
||
10 | class FolderManagerTest extends TestCase |
||
11 | { |
||
12 | /** |
||
13 | * @var ObjectRepository |
||
14 | */ |
||
15 | protected $repository; |
||
16 | |||
17 | /** |
||
18 | * @var Folder |
||
19 | */ |
||
20 | protected $folder; |
||
21 | |||
22 | /** |
||
23 | * @var FolderManager |
||
24 | */ |
||
25 | protected $object; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $parents; |
||
31 | |||
32 | protected function setUp() |
||
70 | |||
71 | public function testGetFolderHierarchy() |
||
72 | { |
||
73 | $this->repository |
||
74 | ->expects($this->once()) |
||
75 | ->method('childrenHierarchy') |
||
76 | ->with($this->equalTo($this->folder)) |
||
77 | ->willReturn(array()); |
||
78 | |||
79 | $this->object->getFolderHierarchy($this->folder); |
||
80 | } |
||
81 | |||
82 | public function testGetRootFolderFor() |
||
92 | |||
93 | View Code Duplication | public function testGetParentIds() |
|
102 | |||
103 | View Code Duplication | public function testGetParents() |
|
112 | } |
||
113 |
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..