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 | |||
| 85 | /** @var string */ |
||
| 86 | private $wrapperToken = ''; |
||
| 87 | |||
| 88 | /** @var bool */ |
||
| 89 | private $verifiedViewer = false; |
||
| 90 | |||
| 91 | |||
| 92 | /** |
||
| 93 | * RemoteEvent constructor. |
||
| 94 | * |
||
| 95 | * @param string $class |
||
| 96 | * @param bool $local |
||
| 97 | */ |
||
| 98 | View Code Duplication | function __construct(string $class = '', bool $local = false) { |
|
| 104 | |||
| 105 | |||
| 106 | /** |
||
| 107 | * @return string |
||
| 108 | */ |
||
| 109 | public function getClass(): string { |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param mixed $class |
||
| 115 | * |
||
| 116 | * @return self |
||
| 117 | */ |
||
| 118 | public function setClass($class): self { |
||
| 123 | |||
| 124 | |||
| 125 | /** |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | public function getSource(): string { |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @param string $source |
||
| 134 | * |
||
| 135 | * @return self |
||
| 136 | */ |
||
| 137 | public function setSource(string $source): self { |
||
| 157 | |||
| 158 | |||
| 159 | /** |
||
| 160 | * @return bool |
||
| 161 | */ |
||
| 162 | public function isLocal(): bool { |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param bool $local |
||
| 168 | * |
||
| 169 | * @return self |
||
| 170 | */ |
||
| 171 | public function setLocal(bool $local): self { |
||
| 176 | |||
| 177 | |||
| 178 | /** |
||
| 179 | * @return bool |
||
| 180 | */ |
||
| 181 | public function isAsync(): bool { |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param bool $async |
||
| 187 | * |
||
| 188 | * @return self |
||
| 189 | */ |
||
| 190 | public function setAsync(bool $async): self { |
||
| 195 | |||
| 196 | |||
| 197 | /** |
||
| 198 | * @param bool $verifiedViewer |
||
| 199 | */ |
||
| 200 | public function setVerifiedViewer(bool $verifiedViewer): void { |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return bool |
||
| 206 | */ |
||
| 207 | public function isVerifiedViewer(): bool { |
||
| 210 | |||
| 211 | |||
| 212 | /** |
||
| 213 | * @param string $wrapperToken |
||
| 214 | * |
||
| 215 | * @return RemoteEvent |
||
| 216 | */ |
||
| 217 | public function setWrapperToken(string $wrapperToken): self { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function getWrapperToken(): string { |
||
| 229 | |||
| 230 | |||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | /** |
||
| 235 | * @return bool |
||
| 236 | */ |
||
| 237 | public function hasCircle(): bool { |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param Circle $circle |
||
| 243 | * |
||
| 244 | * @return self |
||
| 245 | */ |
||
| 246 | public function setCircle(Circle $circle): self { |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @return Circle |
||
| 254 | */ |
||
| 255 | public function getCircle(): Circle { |
||
| 258 | |||
| 259 | |||
| 260 | /** |
||
| 261 | * @return Member |
||
| 262 | */ |
||
| 263 | public function getMember(): Member { |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param Member $member |
||
| 269 | * |
||
| 270 | * @return self |
||
| 271 | */ |
||
| 272 | public function setMember(Member $member): self { |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return bool |
||
| 280 | */ |
||
| 281 | public function hasMember(): bool { |
||
| 284 | |||
| 285 | |||
| 286 | /** |
||
| 287 | * @param SimpleDataStore $data |
||
| 288 | * |
||
| 289 | * @return self |
||
| 290 | */ |
||
| 291 | public function setData(SimpleDataStore $data): self { |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @return SimpleDataStore |
||
| 299 | */ |
||
| 300 | public function getData(): SimpleDataStore { |
||
| 303 | |||
| 304 | |||
| 305 | /** |
||
| 306 | * @return int |
||
| 307 | */ |
||
| 308 | public function getSeverity(): int { |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @param int $severity |
||
| 314 | * |
||
| 315 | * @return self |
||
| 316 | */ |
||
| 317 | public function setSeverity(int $severity): self { |
||
| 322 | |||
| 323 | |||
| 324 | /** |
||
| 325 | * @return SimpleDataStore |
||
| 326 | */ |
||
| 327 | public function getResult(): SimpleDataStore { |
||
| 330 | |||
| 331 | /** |
||
| 332 | * @param SimpleDataStore $result |
||
| 333 | * |
||
| 334 | * @return self |
||
| 335 | */ |
||
| 336 | public function setResult(SimpleDataStore $result): self { |
||
| 341 | |||
| 342 | |||
| 343 | /** |
||
| 344 | * @param array $data |
||
| 345 | * |
||
| 346 | * @return self |
||
| 347 | */ |
||
| 348 | public function import(array $data): self { |
||
| 370 | |||
| 371 | |||
| 372 | /** |
||
| 373 | * @return array |
||
| 374 | */ |
||
| 375 | function jsonSerialize(): array { |
||
| 394 | |||
| 395 | |||
| 396 | } |
||
| 397 | |||
| 398 |
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.