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 |
||
11 | class JSONTextTest extends SapphireTest |
||
|
|||
12 | { |
||
13 | /** |
||
14 | * @todo There are a ton more permutations of a JSONPath regex |
||
15 | * See the walk() method in JSONStore |
||
16 | */ |
||
17 | View Code Duplication | public function testIsValidExpression() |
|
27 | |||
28 | /** |
||
29 | * @return void |
||
30 | */ |
||
31 | public function testIsValidJson() |
||
47 | |||
48 | |||
49 | /** |
||
50 | * Ordinarily we can just use !is_null(json_decode($json)) but SS allows empty strings passed to setValue() so we need |
||
51 | * to allow otherwise invalid JSON by means of an optional 2nd param |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | View Code Duplication | public function testIsValidDBValue() |
|
66 | } |
||
67 |
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.