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 |
||
5 | use SilverStripe\Dev\SapphireTest; |
||
6 | use AntonyThorpe\Knockout\KnockoutPasswordField; |
||
7 | |||
8 | /** |
||
9 | * KnockoutPasswordFieldTest |
||
10 | */ |
||
11 | class KnockoutPasswordFieldTest extends SapphireTest |
||
12 | { |
||
13 | public function testKnockoutPasswordField() |
||
14 | { |
||
15 | $field = KnockoutPasswordField::create("MyField", "My Field") |
||
16 | ->setHasFocus(true); |
||
17 | |||
18 | $this->assertEquals( |
||
19 | "password", |
||
20 | $field->getObservable(), |
||
21 | "observable is set to password by default" |
||
22 | ); |
||
29 |