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 | ||
| 6 | class FormElementTest extends TestCase | ||
|  | |||
| 7 | { | ||
| 8 | /** | ||
| 9 | * @return FormElement | ||
| 10 | */ | ||
| 11 | protected function getElement() | ||
| 15 | |||
| 16 | /** | ||
| 17 | * @covers FormElement::initialize | ||
| 18 | */ | ||
| 19 | public function test_initializable() | ||
| 25 | |||
| 26 | /** | ||
| 27 | * @covers FormElement::getValidationRules | ||
| 28 | * @covers FormElement::addValidationRule | ||
| 29 | */ | ||
| 30 | public function test_adds_validation_rule() | ||
| 40 | |||
| 41 | /** | ||
| 42 | * @covers FormElement::getValidationRules | ||
| 43 | * @covers FormElement::addValidationRule | ||
| 44 | * @covers FormElement::addValidationMessage | ||
| 45 | * @covers FormElement::getValidationMessages | ||
| 46 | */ | ||
| 47 | public function test_adds_validation_rule_with_message() | ||
| 62 | |||
| 63 | /** | ||
| 64 | * @covers FormElement::getValidationMessages | ||
| 65 | * @covers FormElement::addValidationMessage | ||
| 66 | */ | ||
| 67 | public function test_adds_validation_message() | ||
| 84 | |||
| 85 | /** | ||
| 86 | * @covers FormElement::getValidationMessages | ||
| 87 | * @covers FormElement::setValidationMessages | ||
| 88 | */ | ||
| 89 | public function test_sets_validation_messages() | ||
| 107 | |||
| 108 | /** | ||
| 109 | * @covers FormElement::getValidationRules | ||
| 110 | * @covers FormElement::setValidationRules | ||
| 111 | */ | ||
| 112 | View Code Duplication | public function test_sets_validation_rules_as_array() | |
| 126 | |||
| 127 | /** | ||
| 128 | * @covers FormElement::getValidationRules | ||
| 129 | * @covers FormElement::setValidationRules | ||
| 130 | */ | ||
| 131 | View Code Duplication | public function test_sets_validation_rules_as_arguments() | |
| 141 | |||
| 142 | /** | ||
| 143 | * @covers FormElement::getView | ||
| 144 | */ | ||
| 145 | public function test_get_default_view() | ||
| 153 | |||
| 154 | /** | ||
| 155 | * @covers FormElement::setView | ||
| 156 | */ | ||
| 157 | public function test_set_view() | ||
| 164 | |||
| 165 | /** | ||
| 166 | * @covers FormElement::getModel | ||
| 167 | * @covers FormElement::setModel | ||
| 168 | */ | ||
| 169 | public function test_get_and_set_model() | ||
| 179 | |||
| 180 | /** | ||
| 181 | * @covers FormElement::toArray | ||
| 182 | */ | ||
| 183 | public function test_is_arrayable() | ||
| 189 | |||
| 190 | /** | ||
| 191 | * @covers FormElement::render | ||
| 192 | */ | ||
| 193 | public function test_render() | ||
| 203 | |||
| 204 | /** | ||
| 205 | * @covers FormElement::__toString | ||
| 206 | */ | ||
| 207 | public function test_converts_into_string() | ||
| 216 | |||
| 217 | /** | ||
| 218 | * @covers FormElement::isReadonly | ||
| 219 | * @covers FormElement::setReadonly | ||
| 220 | */ | ||
| 221 | public function test_readOnly() | ||
| 242 | |||
| 243 | /** | ||
| 244 | * @covers FormElement::setVisibilityCondition | ||
| 245 | * @covers FormElement::isVisible | ||
| 246 | */ | ||
| 247 | public function test_visibility() | ||
| 260 | } | ||
| 261 | 
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.