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 | class _RSAPublicKeyPEMFormat |
||
22 | extends _AbstractRSAKeyPEMFormat |
||
23 | implements RSAPublicKey { |
||
24 | |||
25 | /** |
||
26 | * @var BigInteger |
||
27 | */ |
||
28 | protected $e; |
||
29 | |||
30 | /** |
||
31 | * @param $pem_format |
||
32 | * @param string $password |
||
33 | * @throws RSABadPEMFormat |
||
34 | */ |
||
35 | public function __construct($pem_format, $password = null){ |
||
39 | |||
40 | /** |
||
41 | * The "e" (exponent) |
||
42 | * @return BigInteger |
||
43 | */ |
||
44 | public function getPublicExponent() |
||
48 | |||
49 | /** |
||
50 | * @return string |
||
51 | */ |
||
52 | public function getAlgorithm() |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getEncoded() |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getFormat() |
||
72 | |||
73 | /** |
||
74 | * @return int |
||
75 | */ |
||
76 | public function getBitLength() |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | View Code Duplication | public function getStrippedEncoded(): string |
|
91 | } |
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.