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 |
||
| 7 | class AbstractCacheTest extends \PHPUnit_Framework_TestCase |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var AbstractCache |
||
| 11 | */ |
||
| 12 | protected $object; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Sets up the fixture, for example, opens a network connection. |
||
| 16 | * This method is called before a test is executed. |
||
| 17 | */ |
||
| 18 | public function setUp() |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Tears down the fixture, for example, closes a network connection. |
||
| 28 | * This method is called after a test is executed. |
||
| 29 | */ |
||
| 30 | public function tearDown() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @covers Koch\Cache\AbstractCache::__construct |
||
| 37 | * @covers Koch\Autoload\Loader::autoload |
||
| 38 | */ |
||
| 39 | public function testConstructor() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @covers Koch\Cache\AbstractCache::setOptions |
||
| 51 | * @covers Koch\Cache\AbstractCache::setOption |
||
| 52 | */ |
||
| 53 | public function testSetOptions() |
||
| 64 | |||
| 65 | public static function SetOptionDataprovider() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @covers Koch\Cache\AbstractCache::setOption |
||
| 75 | * @dataProvider SetOptionDataprovider |
||
| 76 | */ |
||
| 77 | public function testSetOption($key, $value) |
||
| 82 | |||
| 83 | public static function SetOptionDataproviderInvalidData() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @covers Koch\Cache\AbstractCache::setOption |
||
| 94 | * @covers Koch\Cache\AbstractCache::setOptions |
||
| 95 | * @dataProvider SetOptionDataproviderInvalidData |
||
| 96 | * @expectedException InvalidArgumentException |
||
| 97 | */ |
||
| 98 | public function testSetOption_throwsException($key, $value) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @covers Koch\Cache\AbstractCache::setPrefix |
||
| 105 | * @covers Koch\Cache\AbstractCache::getPrefix |
||
| 106 | */ |
||
| 107 | public function testSetPrefix() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @covers Koch\Cache\AbstractCache::setPrefix |
||
| 116 | * @expectedException \InvalidArgumentException |
||
| 117 | * @expectedExceptionMessage Prefix must not be empty. |
||
| 118 | */ |
||
| 119 | public function testSetPrefix_throwsException() |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @covers Koch\Cache\AbstractCache::prefixKey |
||
| 126 | */ |
||
| 127 | public function testApplyPrefix() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @covers Koch\Cache\AbstractCache::__set |
||
| 137 | * @covers Koch\Cache\AbstractCache::__isset |
||
| 138 | * @covers Koch\Cache\AbstractCache::__get |
||
| 139 | * @covers Koch\Cache\AbstractCache::__unset |
||
| 140 | */ |
||
| 141 | View Code Duplication | public function testSet() |
|
| 153 | } |
||
| 154 |
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..