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 |
||
| 19 | abstract class DriverTestAbstract extends TestAbstract{ |
||
| 20 | |||
| 21 | protected $SQL_RAW_TRUNCATE = 'DELETE FROM test'; |
||
| 22 | protected $SQL_RAW_SELECT_ALL = 'SELECT * FROM test'; |
||
| 23 | protected $SQL_RAW_DROP = 'DROP TABLE IF EXISTS test'; |
||
| 24 | protected $SQL_RAW_CREATE = 'CREATE TABLE IF NOT EXISTS test (id INTEGER NOT NULL, hash VARCHAR(32) NOT NULL)'; |
||
| 25 | protected $SQL_RAW_INSERT = 'INSERT INTO test (id, hash) VALUES (%1$d, \'%2$s\')'; |
||
| 26 | protected $SQL_RAW_ERROR = '-'; |
||
| 27 | |||
| 28 | protected $SQL_PREPARED_INSERT = 'INSERT INTO test (id, hash) VALUES (?, ?)'; |
||
| 29 | |||
| 30 | protected $SQL_INDEX_COL = 'id'; |
||
| 31 | protected $SQL_DATA_COL = 'hash'; |
||
| 32 | |||
| 33 | protected $SQL_ESCAPED; |
||
| 34 | protected $SQL_QUOTES; |
||
| 35 | protected $SQL_DIALECT; |
||
| 36 | |||
| 37 | protected function tearDown(){ |
||
| 40 | |||
| 41 | public function testInstance(){ |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @expectedException \chillerlan\Database\DBException |
||
| 59 | * @expectedExceptionMessage db error: |
||
| 60 | */ |
||
| 61 | public function testConnectDBconnectError(){ |
||
| 66 | |||
| 67 | // coverage |
||
| 68 | public function testEscape(){ |
||
| 71 | |||
| 72 | public function testCreateTable(){ |
||
| 76 | |||
| 77 | public function testTruncate(){ |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @expectedException \chillerlan\Database\DBException |
||
| 84 | * @expectedExceptionMessage sql error: |
||
| 85 | */ |
||
| 86 | public function testRawSQLError(){ |
||
| 89 | |||
| 90 | protected function resultTest(){ |
||
| 115 | |||
| 116 | public function testRaw(){ |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @expectedException \chillerlan\Database\DBException |
||
| 128 | * @expectedExceptionMessage sql error: |
||
| 129 | */ |
||
| 130 | public function testPreparedSQLError(){ |
||
| 133 | |||
| 134 | View Code Duplication | public function testPrepared(){ |
|
| 142 | |||
| 143 | /** |
||
| 144 | * @expectedException \chillerlan\Database\DBException |
||
| 145 | * @expectedExceptionMessage invalid data |
||
| 146 | */ |
||
| 147 | public function testMultiInvalidData(){ |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @expectedException \chillerlan\Database\DBException |
||
| 153 | * @expectedExceptionMessage sql error: |
||
| 154 | */ |
||
| 155 | public function testMultiSQLError(){ |
||
| 158 | |||
| 159 | View Code Duplication | public function testMulti(){ |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @expectedException \chillerlan\Database\DBException |
||
| 176 | * @expectedExceptionMessage invalid data |
||
| 177 | */ |
||
| 178 | public function testMultiCallbackInvalidData(){ |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @expectedException \chillerlan\Database\DBException |
||
| 186 | * @expectedExceptionMessage invalid callback |
||
| 187 | */ |
||
| 188 | public function testMultiCallbackInvalidCallback(){ |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @expectedException \chillerlan\Database\DBException |
||
| 194 | * @expectedExceptionMessage sql error: |
||
| 195 | */ |
||
| 196 | public function testMultiCallbackSQLError(){ |
||
| 202 | |||
| 203 | View Code Duplication | public function testMultiCallback(){ |
|
| 212 | |||
| 213 | public function testCached(){ |
||
| 249 | |||
| 250 | } |
||
| 251 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: