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 |
||
17 | final class JsonRpcRequest implements JsonRpcRequestInterface |
||
18 | { |
||
19 | /** @var string|null */ |
||
20 | private $id; |
||
21 | /** @var string */ |
||
22 | private $method; |
||
23 | /** @var mixed|\stdClass */ |
||
24 | private $parameters; |
||
25 | |||
26 | /** @return bool True if request should not receive response from the server */ |
||
27 | 7 | public function isNotification() |
|
31 | |||
32 | /** |
||
33 | * @param \stdClass $source |
||
34 | * |
||
35 | * @return JsonRpcRequestInterface |
||
36 | * @throws JsonRpcException |
||
37 | */ |
||
38 | 7 | public static function fromStdClass(\stdClass $source) |
|
63 | |||
64 | /** {@inheritdoc} */ |
||
65 | View Code Duplication | public function jsonSerialize() |
|
74 | |||
75 | /** {@inheritdoc} */ |
||
76 | public function getVersion() |
||
80 | |||
81 | /** @return string */ |
||
82 | 7 | public function getMethod() |
|
86 | |||
87 | /** @return array */ |
||
88 | 6 | public function getParameters() |
|
92 | |||
93 | /** @return int|null Id. if not a notification and id is not set - id should be automatically generated */ |
||
94 | 7 | public function getId() |
|
98 | } |
||
99 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.