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 | public const VAULT_CONFIG_CLASS = VaultConfiguration::class; |
||
| 13 | |||
| 14 | |||
| 15 | /** |
||
| 16 | * The local base path of the archive. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $path; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Set of excluded paths. |
||
| 24 | * |
||
| 25 | * @var string[] |
||
| 26 | */ |
||
| 27 | protected $exclude = []; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Identity to be visible in synchronization log. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $identity; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Map of vault configurations by identifier. |
||
| 38 | * |
||
| 39 | * @var VaultConfiguration[] |
||
| 40 | */ |
||
| 41 | protected $vaults = []; |
||
| 42 | |||
| 43 | public function __construct(string $localPath = './') |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public function getPath(): string |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param string $path |
||
| 58 | * |
||
| 59 | * @return Configuration |
||
| 60 | */ |
||
| 61 | public function setPath(string $path): Configuration |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @return \string[] |
||
| 75 | */ |
||
| 76 | public function getExclude(): array |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @param \string[] $paths |
||
| 83 | * |
||
| 84 | * @return Configuration |
||
| 85 | */ |
||
| 86 | public function setExclude(array $paths): Configuration |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param string $path |
||
| 95 | * |
||
| 96 | * @return Configuration |
||
| 97 | */ |
||
| 98 | public function addExclusion(string $path): Configuration |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getIdentity(): ?string |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $identity |
||
| 115 | * |
||
| 116 | * @return Configuration |
||
| 117 | */ |
||
| 118 | public function setIdentity(string $identity): Configuration |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return VaultConfiguration[] |
||
| 127 | */ |
||
| 128 | public function getVaults(): array |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param string $title |
||
| 135 | * @return bool |
||
| 136 | */ |
||
| 137 | public function hasVault(string $title): bool |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param string $title |
||
| 144 | * |
||
| 145 | * @return VaultConfiguration |
||
| 146 | */ |
||
| 147 | public function getVaultByTitle(string $title): VaultConfiguration |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @param VaultConfiguration $configuration |
||
| 159 | * |
||
| 160 | * @return Configuration |
||
| 161 | * @throws Exception |
||
| 162 | */ |
||
| 163 | public function addVault(VaultConfiguration $configuration): Configuration |
||
| 174 | |||
| 175 | /** |
||
| 176 | * {@inheritdoc} |
||
| 177 | */ |
||
| 178 | public function exchangeArray(array $array) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * {@inheritdoc} |
||
| 222 | */ |
||
| 223 | public function getArrayCopy() |
||
| 234 | |||
| 235 | public static function loadValidatorMetadata(ClassMetadata $metadata) |
||
| 236 | { |
||
| 242 |
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..