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 |
||
14 | abstract class OpenSSLSignatureAlgorithm implements SignatureAlgorithm |
||
15 | { |
||
16 | /** |
||
17 | * Public key. |
||
18 | * |
||
19 | * @var AsymmetricPublicKey $_publicKey |
||
20 | */ |
||
21 | protected $_publicKey; |
||
22 | |||
23 | /** |
||
24 | * Private key. |
||
25 | * |
||
26 | * @var AsymmetricPrivateKey|null $_privateKey |
||
27 | */ |
||
28 | protected $_privateKey; |
||
29 | |||
30 | /** |
||
31 | * Get the message digest method name supported by OpenSSL. |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | abstract protected function _mdMethod(); |
||
36 | |||
37 | 12 | public function computeSignature($data) { |
|
58 | |||
59 | 10 | public function validateSignature($data, $signature) { |
|
73 | |||
74 | /** |
||
75 | * Get the last OpenSSL error message. |
||
76 | * |
||
77 | * @return string|null |
||
78 | */ |
||
79 | 4 | View Code Duplication | protected function _getLastOpenSSLError() { |
86 | } |
||
87 |
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.