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 |
||
5 | class MessageEcho extends Message |
||
6 | { |
||
7 | /** |
||
8 | * @var bool |
||
9 | */ |
||
10 | private $isEcho; |
||
11 | |||
12 | /** |
||
13 | * @var int |
||
14 | */ |
||
15 | private $appId; |
||
16 | |||
17 | /** |
||
18 | * @var null|string |
||
19 | */ |
||
20 | private $metadata; |
||
21 | |||
22 | /** |
||
23 | * MessageEcho constructor. |
||
24 | * |
||
25 | * @param bool $isEcho |
||
26 | * @param int $appId |
||
27 | * @param string $id |
||
28 | * @param int $sequence |
||
29 | * @param null|string $metadata |
||
30 | * @param null|string $text |
||
31 | * @param array $attachments |
||
32 | */ |
||
33 | 7 | public function __construct($isEcho, $appId, $id, $sequence, $metadata = null, $text = null, array $attachments = []) |
|
40 | |||
41 | /** |
||
42 | * @return boolean |
||
43 | */ |
||
44 | 1 | public function isEcho() |
|
48 | |||
49 | /** |
||
50 | * @return int |
||
51 | */ |
||
52 | 1 | public function getAppId() |
|
56 | |||
57 | /** |
||
58 | * @return null|string |
||
59 | */ |
||
60 | 2 | public function getMetadata() |
|
64 | |||
65 | /** |
||
66 | * @param array $payload |
||
67 | * |
||
68 | * @return static |
||
69 | */ |
||
70 | 1 | View Code Duplication | public static function create(array $payload) |
78 | } |
||
79 |