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 |
||
21 | final class Uri |
||
22 | { |
||
23 | /** |
||
24 | * Parses a URI. |
||
25 | * |
||
26 | * The returned array contains the following keys: |
||
27 | * |
||
28 | * * "scheme": The scheme part before the "://"; |
||
29 | * * "path": The path part after the "://". |
||
30 | * |
||
31 | * The URI must fulfill a few constraints: |
||
32 | * |
||
33 | * * the scheme must consist of alphabetic characters only; |
||
34 | * * the scheme may be omitted. Then "://" must be omitted too; |
||
35 | * * the path must not be empty; |
||
36 | * * the path must start with a forward slash ("/"). |
||
37 | * |
||
38 | * If any of these constraints is not fulfilled, an |
||
39 | * {@link InvalidUriException} is thrown. |
||
40 | * |
||
41 | * @param string $uri A URI string. |
||
42 | * |
||
43 | * @return string[] The parts of the URI. |
||
44 | * |
||
45 | * @throws InvalidUriException If the URI is invalid. |
||
46 | */ |
||
47 | 42 | public static function parse($uri) |
|
97 | |||
98 | private function __construct() |
||
101 | } |
||
102 |