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 |
||
| 4 | trait PatternTrait |
||
| 5 | { |
||
| 6 | use XMLPatterns; |
||
| 7 | /** |
||
| 8 | * @Exclude |
||
| 9 | * @var array defines the exact sequence of characters that are acceptable |
||
| 10 | */ |
||
| 11 | public $pattern = array(); |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param string $newPatternToAdd |
||
| 15 | * @param mixed $processMultiCharacterEscape |
||
| 16 | */ |
||
| 17 | protected function setPatternFacet($newPatternToAdd, $processMultiCharacterEscape = true) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @param string $patternToProcess |
||
| 35 | * @param bool $processMultiCharacterEscape |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | private function processRegex($patternToProcess, $processMultiCharacterEscape) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $patternToProcess |
||
| 57 | * |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | View Code Duplication | private function processRegexSlashS($patternToProcess) |
|
| 68 | |||
| 69 | /** |
||
| 70 | * @param string $patternToProcess |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | private function processRegexSlashI($patternToProcess) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param string $patternToProcess |
||
| 88 | * |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | private function processRegexSlashC($patternToProcess) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param string $patternToProcess |
||
| 106 | * |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | View Code Duplication | private function processRegexSlashD($patternToProcess) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @param string $patternToProcess |
||
| 120 | * |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | View Code Duplication | private function processRegexSlashW($patternToProcess) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * @param string $pattern |
||
| 137 | * |
||
| 138 | * @return bool |
||
| 139 | */ |
||
| 140 | private function checkRegexValidPattern($pattern) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param string $v |
||
| 147 | */ |
||
| 148 | private function checkPattern($v) |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Checks a pattern against a string. |
||
| 162 | * |
||
| 163 | * @param string $pattern the regex pattern |
||
| 164 | * @param string $string the string to check |
||
| 165 | * @return bool true if string matches pattern |
||
| 166 | */ |
||
| 167 | private function matchesRegexPattern($pattern, $string) |
||
| 172 | } |
||
| 173 |