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\KnockoutEmailField; |
||
7 | |||
8 | /** |
||
9 | * KnockoutEmailFieldTest |
||
10 | */ |
||
11 | class KnockoutEmailFieldTest extends SapphireTest |
||
12 | { |
||
13 | |||
14 | public function testKnockoutEmailField() |
||
15 | { |
||
16 | $field = KnockoutEmailField::create("MyField", "My Field") |
||
17 | ->setObservable('email') |
||
18 | ->setHasFocus(true); |
||
19 | $this->assertEquals( |
||
20 | "email", |
||
21 | $field->getObservable(), |
||
22 | "observable is set" |
||
23 | ); |
||
30 |