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 |
||
3 | class Wikipedia |
||
|
|||
4 | { |
||
5 | const URL = 'https://en.wikipedia.org/w/api.php?action=query&titles=Microsoft_Edge&prop=revisions&rvprop=content&rvsection=4&format=xml'; |
||
6 | |||
7 | private static $errors = array( |
||
8 | 'fetch_error' => 'Unable to fetch content', |
||
9 | 'parse_error' => 'Unable to parse content', |
||
10 | ); |
||
11 | |||
12 | public static function fetch() |
||
24 | |||
25 | private static function extractVersion($content) |
||
40 | |||
41 | View Code Duplication | private static function writeEdgeVersions($versions) |
|
65 | } |
||
66 |
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.