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 |
||
| 8 | class Configuration implements ArraySerializableInterface |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The local base path of the archive. |
||
| 12 | * |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | protected $path; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Set of excluded paths. |
||
| 19 | * |
||
| 20 | * @var string[] |
||
| 21 | */ |
||
| 22 | protected $exclude = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Identity to be visible in synchronization log. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $identity; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Map of vault configurations by identifier. |
||
| 33 | * |
||
| 34 | * @var VaultConfiguration[] |
||
| 35 | */ |
||
| 36 | protected $vaults = []; |
||
| 37 | |||
| 38 | public function __construct(string $localPath = './') |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | public function getPath(): string |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param string $path |
||
| 53 | * |
||
| 54 | * @return Configuration |
||
| 55 | */ |
||
| 56 | public function setPath(string $path): Configuration |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return \string[] |
||
| 70 | */ |
||
| 71 | public function getExclude(): array |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param \string[] $paths |
||
| 78 | * |
||
| 79 | * @return Configuration |
||
| 80 | */ |
||
| 81 | public function setExclude(array $paths): Configuration |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param string $path |
||
| 90 | * |
||
| 91 | * @return Configuration |
||
| 92 | */ |
||
| 93 | public function addExclusion(string $path): Configuration |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @return string |
||
| 102 | */ |
||
| 103 | public function getIdentity() |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param string $identity |
||
| 110 | * |
||
| 111 | * @return Configuration |
||
| 112 | */ |
||
| 113 | public function setIdentity(string $identity): Configuration |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return VaultConfiguration[] |
||
| 122 | */ |
||
| 123 | public function getVaults(): array |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param string $title |
||
| 130 | * @return bool |
||
| 131 | */ |
||
| 132 | public function hasVault(string $title): bool |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param string $title |
||
| 139 | * |
||
| 140 | * @return VaultConfiguration |
||
| 141 | */ |
||
| 142 | public function getVaultByTitle(string $title) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param VaultConfiguration $configuration |
||
| 154 | * |
||
| 155 | * @return Configuration |
||
| 156 | * @throws Exception |
||
| 157 | */ |
||
| 158 | public function addVault(VaultConfiguration $configuration): Configuration |
||
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | public function exchangeArray(array $array) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | */ |
||
| 215 | public function getArrayCopy() |
||
| 226 | } |
||
| 227 |
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..