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 |
||
17 | class TSchemaType extends IsOK |
||
18 | { |
||
19 | use GSchemaBodyElementsTrait, TSimpleIdentifierTrait, XSDTopLevelTrait, TNamespaceNameTrait { |
||
20 | TSimpleIdentifierTrait::isNCName insteadof TNamespaceNameTrait; |
||
21 | TSimpleIdentifierTrait::matchesRegexPattern insteadof TNamespaceNameTrait; |
||
22 | TSimpleIdentifierTrait::isName insteadof TNamespaceNameTrait; |
||
23 | |||
24 | |||
25 | } |
||
26 | /** |
||
27 | * @property string $namespace |
||
28 | */ |
||
29 | private $namespace = null; |
||
30 | |||
31 | /** |
||
32 | * @property string $namespaceUri |
||
33 | */ |
||
34 | private $namespaceUri = null; |
||
35 | |||
36 | /** |
||
37 | * @property string $alias |
||
38 | */ |
||
39 | private $alias = null; |
||
40 | |||
41 | /** |
||
42 | * Gets as namespaceUri |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | public function getNamespaceUri() |
||
47 | { |
||
48 | return $this->namespaceUri; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Sets a new namespaceUri |
||
53 | * |
||
54 | * @param string $namespaceUri |
||
55 | * @return self |
||
56 | */ |
||
57 | public function setNamespaceUri($namespaceUri) |
||
58 | { |
||
59 | if (null != $namespaceUri && !$this->isURLValid($namespaceUri)) { |
||
60 | $msg = "Namespace url must be a valid url"; |
||
61 | throw new \InvalidArgumentException($msg); |
||
62 | } |
||
63 | $this->namespaceUri = $namespaceUri; |
||
64 | return $this; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Gets as alias |
||
69 | * |
||
70 | * @return string |
||
71 | */ |
||
72 | public function getAlias() |
||
76 | |||
77 | /** |
||
78 | * Sets a new alias |
||
79 | * |
||
80 | * @param string $alias |
||
81 | * @return self |
||
82 | */ |
||
83 | public function setAlias($alias) |
||
92 | |||
93 | public function isOK(&$msg = null) |
||
94 | { |
||
112 | |||
113 | public function isStructureOK(&$msg = null) |
||
168 | |||
169 | /** |
||
170 | * Gets as namespace |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | public function getNamespace() |
||
178 | |||
179 | /** |
||
180 | * Sets a new namespace |
||
181 | * |
||
182 | * @param string $namespace |
||
183 | * @return self |
||
184 | */ |
||
185 | public function setNamespace($namespace) |
||
194 | } |
||
195 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.