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 |
||
3 | class LocatorTest extends Locator_Test |
||
4 | { |
||
5 | public function testGetCMSFields() |
||
11 | |||
12 | View Code Duplication | public function testLocations() |
|
13 | { |
||
14 | $filter = array('ShowInLocator' => 1); |
||
15 | $filterAny = array('Suburb' => 'Sheboygan'); |
||
16 | $exclude = array('Suburb' => 'Milwaukee'); |
||
17 | $locations = Locator::locations($filter, $filterAny, $exclude); |
||
18 | $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
||
19 | $this->assertEquals($locations->Count(), $locations2->Count()); |
||
20 | } |
||
21 | |||
22 | public function testGetAllCategories() |
||
28 | |||
29 | public function testGetPageCategories() |
||
41 | |||
42 | public function testInit() |
||
45 | |||
46 | public function testIndex() |
||
47 | { |
||
48 | $locator = $this->objFromFixture('Locator', 'locator1'); |
||
49 | $controller = Locator_Controller::create($locator); |
||
50 | $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
||
1 ignored issue
–
show
|
|||
51 | } |
||
52 | |||
53 | public function testXml() |
||
59 | |||
60 | View Code Duplication | public function testItems() |
|
61 | { |
||
72 | |||
73 | public function testLocationSearch() |
||
89 | } |
||
90 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.