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 |
||
| 47 | class RemoteEvent implements JsonSerializable { |
||
| 48 | |||
| 49 | |||
| 50 | const SEVERITY_LOW = 1; |
||
| 51 | const SEVERITY_HIGH = 3; |
||
| 52 | |||
| 53 | |||
| 54 | use TArrayTools; |
||
| 55 | |||
| 56 | |||
| 57 | /** @var string */ |
||
| 58 | private $class; |
||
| 59 | |||
| 60 | /** @var string */ |
||
| 61 | private $source = ''; |
||
| 62 | |||
| 63 | /** @var Circle */ |
||
| 64 | private $circle; |
||
| 65 | |||
| 66 | /** @var Member */ |
||
| 67 | private $member; |
||
| 68 | |||
| 69 | /** @var SimpleDataStore */ |
||
| 70 | private $data; |
||
| 71 | |||
| 72 | /** @var int */ |
||
| 73 | private $severity = self::SEVERITY_LOW; |
||
| 74 | |||
| 75 | /** @var SimpleDataStore */ |
||
| 76 | private $result; |
||
| 77 | |||
| 78 | /** @var bool */ |
||
| 79 | private $local; |
||
| 80 | |||
| 81 | /** @var bool */ |
||
| 82 | private $async = false; |
||
| 83 | |||
| 84 | /** @var string */ |
||
| 85 | private $incomingOrigin = ''; |
||
| 86 | |||
| 87 | |||
| 88 | /** @var string */ |
||
| 89 | private $wrapperToken = ''; |
||
| 90 | |||
| 91 | /** @var bool */ |
||
| 92 | private $verifiedViewer = false; |
||
| 93 | |||
| 94 | /** @var bool */ |
||
| 95 | private $verifiedCircle = false; |
||
| 96 | |||
| 97 | |||
| 98 | /** |
||
| 99 | * RemoteEvent constructor. |
||
| 100 | * |
||
| 101 | * @param string $class |
||
| 102 | * @param bool $local |
||
| 103 | */ |
||
| 104 | View Code Duplication | function __construct(string $class = '', bool $local = false) { |
|
| 110 | |||
| 111 | |||
| 112 | /** |
||
| 113 | * @return string |
||
| 114 | */ |
||
| 115 | public function getClass(): string { |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @param mixed $class |
||
| 121 | * |
||
| 122 | * @return self |
||
| 123 | */ |
||
| 124 | public function setClass($class): self { |
||
| 129 | |||
| 130 | |||
| 131 | /** |
||
| 132 | * @return string |
||
| 133 | */ |
||
| 134 | public function getSource(): string { |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param string $source |
||
| 140 | * |
||
| 141 | * @return self |
||
| 142 | */ |
||
| 143 | public function setSource(string $source): self { |
||
| 163 | |||
| 164 | |||
| 165 | /** |
||
| 166 | * @return bool |
||
| 167 | */ |
||
| 168 | public function isLocal(): bool { |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param bool $local |
||
| 174 | * |
||
| 175 | * @return self |
||
| 176 | */ |
||
| 177 | public function setLocal(bool $local): self { |
||
| 182 | |||
| 183 | |||
| 184 | /** |
||
| 185 | * @return bool |
||
| 186 | */ |
||
| 187 | public function isAsync(): bool { |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param bool $async |
||
| 193 | * |
||
| 194 | * @return self |
||
| 195 | */ |
||
| 196 | public function setAsync(bool $async): self { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param string $incomingOrigin |
||
| 204 | * |
||
| 205 | * @return self |
||
| 206 | */ |
||
| 207 | public function setIncomingOrigin(string $incomingOrigin): self { |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | public function getIncomingOrigin(): string { |
||
| 219 | |||
| 220 | |||
| 221 | /** |
||
| 222 | * @param bool $verifiedViewer |
||
| 223 | * |
||
| 224 | * @return RemoteEvent |
||
| 225 | */ |
||
| 226 | public function setVerifiedViewer(bool $verifiedViewer): self { |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @return bool |
||
| 234 | */ |
||
| 235 | public function isVerifiedViewer(): bool { |
||
| 238 | |||
| 239 | |||
| 240 | /** |
||
| 241 | * @param bool $verifiedCircle |
||
| 242 | * |
||
| 243 | * @return RemoteEvent |
||
| 244 | */ |
||
| 245 | public function setVerifiedCircle(bool $verifiedCircle): self { |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return bool |
||
| 253 | */ |
||
| 254 | public function isVerifiedCircle(): bool { |
||
| 257 | |||
| 258 | |||
| 259 | /** |
||
| 260 | * @param string $wrapperToken |
||
| 261 | * |
||
| 262 | * @return RemoteEvent |
||
| 263 | */ |
||
| 264 | public function setWrapperToken(string $wrapperToken): self { |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return string |
||
| 272 | */ |
||
| 273 | public function getWrapperToken(): string { |
||
| 276 | |||
| 277 | |||
| 278 | /** |
||
| 279 | * @return bool |
||
| 280 | */ |
||
| 281 | public function hasCircle(): bool { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param Circle $circle |
||
| 287 | * |
||
| 288 | * @return self |
||
| 289 | */ |
||
| 290 | public function setCircle(Circle $circle): self { |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @return Circle |
||
| 298 | */ |
||
| 299 | public function getCircle(): Circle { |
||
| 302 | |||
| 303 | |||
| 304 | /** |
||
| 305 | * @return Member |
||
| 306 | */ |
||
| 307 | public function getMember(): Member { |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @param Member $member |
||
| 313 | * |
||
| 314 | * @return self |
||
| 315 | */ |
||
| 316 | public function setMember(Member $member): self { |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return bool |
||
| 324 | */ |
||
| 325 | public function hasMember(): bool { |
||
| 328 | |||
| 329 | |||
| 330 | /** |
||
| 331 | * @param SimpleDataStore $data |
||
| 332 | * |
||
| 333 | * @return self |
||
| 334 | */ |
||
| 335 | public function setData(SimpleDataStore $data): self { |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return SimpleDataStore |
||
| 343 | */ |
||
| 344 | public function getData(): SimpleDataStore { |
||
| 347 | |||
| 348 | |||
| 349 | /** |
||
| 350 | * @return int |
||
| 351 | */ |
||
| 352 | public function getSeverity(): int { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @param int $severity |
||
| 358 | * |
||
| 359 | * @return self |
||
| 360 | */ |
||
| 361 | public function setSeverity(int $severity): self { |
||
| 366 | |||
| 367 | |||
| 368 | /** |
||
| 369 | * @return SimpleDataStore |
||
| 370 | */ |
||
| 371 | public function getResult(): SimpleDataStore { |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @param SimpleDataStore $result |
||
| 377 | * |
||
| 378 | * @return self |
||
| 379 | */ |
||
| 380 | public function setResult(SimpleDataStore $result): self { |
||
| 385 | |||
| 386 | |||
| 387 | /** |
||
| 388 | * @param array $data |
||
| 389 | * |
||
| 390 | * @return self |
||
| 391 | */ |
||
| 392 | public function import(array $data): self { |
||
| 414 | |||
| 415 | |||
| 416 | /** |
||
| 417 | * @return array |
||
| 418 | */ |
||
| 419 | function jsonSerialize(): array { |
||
| 438 | |||
| 439 | |||
| 440 | } |
||
| 441 | |||
| 442 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.