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 |
||
28 | View Code Duplication | class xsLanguage extends xsToken |
|
29 | { |
||
30 | /** |
||
31 | * Construct. |
||
32 | * |
||
33 | * @param string $value |
||
34 | */ |
||
35 | public function __construct($value) |
||
36 | { |
||
37 | parent::__construct($value); |
||
38 | /* |
||
39 | * Match a single character present in the list below [a-zA-Z]{1,8} |
||
40 | * {1,8} Quantifier — Matches between 1 and 8 times, as many times as possible, giving back as needed |
||
41 | * a-z a single character in the range between a (index 97) and z (index 122) (case sensitive) |
||
42 | * A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive) |
||
43 | * 1st Capturing Group (-[a-zA-Z0-9]{1,8})* |
||
44 | * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed |
||
45 | * A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated |
||
46 | * group to capture all iterations or use a non-capturing group instead if you're not interested in the data |
||
47 | * - matches the character - literally (case sensitive) |
||
48 | * Match a single character present in the list below [a-zA-Z0-9]{1,8} |
||
49 | * {1,8} Quantifier — Matches between 1 and 8 times, as many times as possible, giving back as needed |
||
50 | * a-z a single character in the range between a (index 97) and z (index 122) (case sensitive) |
||
51 | * A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive) |
||
52 | * 0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive) |
||
53 | */ |
||
54 | $this->setPatternFacet('[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*'); |
||
55 | $this->setWhiteSpaceFacet('collapse'); |
||
56 | } |
||
57 | |||
58 | protected function fixValue() |
||
64 | |||
65 | protected function isOK() |
||
74 | } |
||
75 |