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 namespace security\rsa; |
||
21 | final class _RSAPrivateKeyPEMFormat |
||
22 | extends _RSAPublicKeyPEMFormat |
||
23 | implements RSAPrivateKey { |
||
24 | |||
25 | /** |
||
26 | * @var BigInteger |
||
27 | */ |
||
28 | private $d; |
||
29 | |||
30 | /** |
||
31 | * @param $pem_format |
||
32 | * @param string $password |
||
33 | * @throws RSABadPEMFormat |
||
34 | */ |
||
35 | public function __construct($pem_format, $password = null){ |
||
42 | |||
43 | /** |
||
44 | * The "d" (private exponent) |
||
45 | * |
||
46 | * @return BigInteger |
||
47 | */ |
||
48 | public function getPrivateExponent() |
||
52 | |||
53 | /** |
||
54 | * @return string |
||
55 | */ |
||
56 | public function getEncoded() |
||
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | public function getFormat() |
||
68 | |||
69 | /** |
||
70 | * @return string |
||
71 | */ |
||
72 | View Code Duplication | public function getStrippedEncoded(): string |
|
79 | |||
80 | } |
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.