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 | class Configuration implements ArraySerializableInterface |
||
11 | { |
||
12 | /** |
||
13 | * The local base path of the archive. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $path; |
||
18 | |||
19 | /** |
||
20 | * Set of excluded paths. |
||
21 | * |
||
22 | * @var string[] |
||
23 | */ |
||
24 | protected $exclude = []; |
||
25 | |||
26 | /** |
||
27 | * Identity to be visible in synchronization log. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $identity; |
||
32 | |||
33 | /** |
||
34 | * Map of vault configurations by identifier. |
||
35 | * |
||
36 | * @var VaultConfiguration[] |
||
37 | */ |
||
38 | protected $vaults = []; |
||
39 | |||
40 | public function __construct(string $localPath = './') |
||
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | public function getPath(): string |
||
52 | |||
53 | /** |
||
54 | * @param string $path |
||
55 | * |
||
56 | * @return Configuration |
||
57 | */ |
||
58 | public function setPath(string $path): Configuration |
||
69 | |||
70 | /** |
||
71 | * @return \string[] |
||
72 | */ |
||
73 | public function getExclude(): array |
||
77 | |||
78 | /** |
||
79 | * @param \string[] $paths |
||
80 | * |
||
81 | * @return Configuration |
||
82 | */ |
||
83 | public function setExclude(array $paths): Configuration |
||
89 | |||
90 | /** |
||
91 | * @param string $path |
||
92 | * |
||
93 | * @return Configuration |
||
94 | */ |
||
95 | public function addExclusion(string $path): Configuration |
||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getIdentity() |
||
109 | |||
110 | /** |
||
111 | * @param string $identity |
||
112 | * |
||
113 | * @return Configuration |
||
114 | */ |
||
115 | public function setIdentity(string $identity): Configuration |
||
121 | |||
122 | /** |
||
123 | * @return VaultConfiguration[] |
||
124 | */ |
||
125 | public function getVaults(): array |
||
129 | |||
130 | /** |
||
131 | * @param string $title |
||
132 | * @return bool |
||
133 | */ |
||
134 | public function hasVault(string $title): bool |
||
138 | |||
139 | /** |
||
140 | * @param string $title |
||
141 | * |
||
142 | * @return VaultConfiguration |
||
143 | */ |
||
144 | public function getVaultByTitle(string $title) |
||
153 | |||
154 | /** |
||
155 | * @param VaultConfiguration $configuration |
||
156 | * |
||
157 | * @return Configuration |
||
158 | * @throws Exception |
||
159 | */ |
||
160 | public function addVault(VaultConfiguration $configuration): Configuration |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | public function exchangeArray(array $array) |
||
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | public function getArrayCopy() |
||
228 | |||
229 | public static function loadValidatorMetadata(ClassMetadata $metadata) |
||
235 | } |
||
236 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..