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