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 |
||
| 10 | abstract class xsAnySimpleType |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @Exclude |
||
| 14 | * @var array Defines a list of acceptable values |
||
| 15 | */ |
||
| 16 | private $enumeration = null; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @Exclude |
||
| 20 | * @var integer Specifies the maximum number of characters or list items allowed. Must be equal to or greater than zero |
||
| 21 | */ |
||
| 22 | private $maxLength = null; |
||
| 23 | /** |
||
| 24 | * @Exclude |
||
| 25 | * @var integer Specifies the minimum number of characters or list items allowed. Must be equal to or greater than zero |
||
| 26 | */ |
||
| 27 | private $minLength = null; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @Exclude |
||
| 31 | * @var string Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled |
||
| 32 | */ |
||
| 33 | private $whiteSpace = "preserve"; |
||
| 34 | /** |
||
| 35 | * @Exclude |
||
| 36 | * @var string Defines the exact sequence of characters that are acceptable |
||
| 37 | */ |
||
| 38 | private $pattern = null; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @property mixed $__value |
||
| 42 | */ |
||
| 43 | private $__value = null; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Construct |
||
| 47 | * |
||
| 48 | * @param mixed $value |
||
| 49 | */ |
||
| 50 | public function __construct($value) |
||
| 54 | |||
| 55 | private function fixValueInteral($value) |
||
| 81 | |||
| 82 | private function checkEnumeration($v) |
||
| 91 | |||
| 92 | View Code Duplication | private function checkMaxLength($v) |
|
| 104 | |||
| 105 | View Code Duplication | private function checkMinLength($v) |
|
| 117 | |||
| 118 | private function checkPattern($v) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Checks a pattern against a string |
||
| 129 | * |
||
| 130 | * @param string $pattern the regex pattern |
||
| 131 | * @param string $string the string to check |
||
| 132 | * @return bool true if string matches pattern |
||
| 133 | */ |
||
| 134 | private function matchesRegexPattern($pattern, $string) |
||
| 139 | |||
| 140 | abstract protected function isOK($value); |
||
| 141 | |||
| 142 | protected function setLengthFacet($value) |
||
| 147 | |||
| 148 | protected function setMinLengthFacet($value) |
||
| 153 | |||
| 154 | private function checkValidMinMaxLength($value, $min = 0) |
||
| 163 | |||
| 164 | protected function setMaxLengthFacet($value) |
||
| 169 | |||
| 170 | protected function setWhiteSpaceFacet($value) |
||
| 177 | |||
| 178 | protected function setPatternFacet($value) |
||
| 188 | |||
| 189 | private function checkRegexValidPattern($pattern) |
||
| 193 | } |
||
| 194 |