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 AbstractModelTest extends PHPUnit_Framework_TestCase |
||
| 9 | { |
||
| 10 | protected $vocabulary = array( |
||
| 11 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
| 12 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
||
| 13 | 'owl' => 'http://www.w3.org/2002/07/owl#', |
||
| 14 | 'xsd' => 'http://www.w3.org/2001/XMLSchema#', |
||
| 15 | 'dct' => 'http://purl.org/dc/terms/', |
||
| 16 | 'void' => 'http://rdfs.org/ns/void#', |
||
| 17 | 'prov' => 'http://www.w3.org/ns/prov#', |
||
| 18 | 'schema' => 'http://schema.org/', |
||
| 19 | 'wgs' => 'http://www.w3.org/2003/01/geo/wgs84_pos#', |
||
| 20 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
||
| 21 | 'dq' => 'http://purl.org/linked-data/cube#', |
||
| 22 | 'daq' => 'http://purl.org/eis/vocab/daq#', |
||
| 23 | 'botk' => 'http://http://linkeddata.center/botk/v1#', |
||
| 24 | ); |
||
| 25 | |||
| 26 | |||
| 27 | /** |
||
| 28 | * @dataProvider data |
||
| 29 | */ |
||
| 30 | public function testConstructor($data, $expectedData) |
||
| 42 | |||
| 43 | |||
| 44 | public function testConstructorWithCustomOptions() |
||
| 61 | |||
| 62 | |||
| 63 | public function testgetVocabularies() |
||
| 69 | |||
| 70 | |||
| 71 | View Code Duplication | public function testSetVocabulary() |
|
| 81 | |||
| 82 | |||
| 83 | View Code Duplication | public function testUnsetVocabulary() |
|
| 93 | |||
| 94 | |||
| 95 | /** |
||
| 96 | * @dataProvider uris |
||
| 97 | */ |
||
| 98 | public function testGetUri($data, $expectedData) |
||
| 113 | |||
| 114 | View Code Duplication | public function testTurtleHeader() |
|
| 124 | |||
| 125 | |||
| 126 | View Code Duplication | public function testTurtleHeaderWithBase() |
|
| 136 | |||
| 137 | |||
| 138 | |||
| 139 | public function testAsString() |
||
| 146 | |||
| 147 | } |
||
| 148 | |||
| 149 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.