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 |
||
8 | class TocifierTest extends PHPUnit_Framework_TestCase |
||
9 | { |
||
10 | public function testProcess() |
||
27 | |||
28 | public function testPrependAnchor() |
||
29 | { |
||
30 | $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
||
31 | $this->assertEquals('', $tocifier->getHtml()); |
||
32 | |||
33 | $tocifier->setAugmentCallback(['\eNTiDi\Autotoc\Tocifier', 'prependAnchor']); |
||
34 | $this->assertTrue($tocifier->process()); |
||
35 | $this->assertStringEqualsFile(__DIR__.'/html1', $tocifier->getHtml()); |
||
36 | } |
||
37 | |||
38 | public function testSetId() |
||
39 | { |
||
40 | $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
||
41 | $this->assertEquals('', $tocifier->getHtml()); |
||
42 | |||
43 | // The default augmenting method should already be setId |
||
44 | $this->assertTrue($tocifier->process()); |
||
45 | $this->assertStringEqualsFile(__DIR__.'/html2', $tocifier->getHtml()); |
||
46 | } |
||
47 | |||
48 | View Code Duplication | public function testTOC() |
|
60 | |||
61 | View Code Duplication | public function testDataHideFromTOC() |
|
75 | } |
||
76 |
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: