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 jwk\impl; |
||
29 | abstract class AsymmetricJWK |
||
30 | extends JWK |
||
31 | implements IAsymmetricJWK |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * @var int |
||
36 | */ |
||
37 | protected $visibility; |
||
38 | |||
39 | /** |
||
40 | * @var PrivateKey |
||
41 | */ |
||
42 | protected $private_key; |
||
43 | |||
44 | /** |
||
45 | * @var PublicKey |
||
46 | */ |
||
47 | protected $public_key; |
||
48 | |||
49 | /** |
||
50 | * @var X509Certificate[] |
||
51 | */ |
||
52 | protected $x509_certificates_chain = []; |
||
53 | |||
54 | /** |
||
55 | * @param array $headers |
||
56 | * @throws X509CertMismatchException |
||
57 | */ |
||
58 | protected function __construct(array $headers = array()) |
||
91 | |||
92 | /** |
||
93 | * @return int |
||
94 | */ |
||
95 | public function getVisibility() |
||
99 | |||
100 | /** |
||
101 | * @param int $visibility |
||
102 | * @return $this |
||
103 | * @throws InvalidJWKVisibilityException |
||
104 | */ |
||
105 | public function setVisibility($visibility) |
||
112 | |||
113 | /** |
||
114 | * @return PrivateKey |
||
115 | */ |
||
116 | public function getPrivateKey() |
||
120 | |||
121 | /** |
||
122 | * @return PublicKey |
||
123 | */ |
||
124 | public function getPublicKey() |
||
128 | |||
129 | /** |
||
130 | * @return null | X509Certificate |
||
131 | */ |
||
132 | public function getX509LeafCertificate(){ |
||
135 | |||
136 | |||
137 | /** |
||
138 | * @return X509Certificate[] |
||
139 | */ |
||
140 | public function getCertificateChain() |
||
144 | |||
145 | /** |
||
146 | * @param bool $fallback_on_x5c |
||
147 | * @return string |
||
148 | */ |
||
149 | View Code Duplication | public function getX509CertificateSha1Thumbprint($fallback_on_x5c = false) |
|
160 | |||
161 | /** |
||
162 | * @param bool $fallback_on_x5c |
||
163 | * @return string |
||
164 | */ |
||
165 | View Code Duplication | public function getX509CertificateSha256Thumbprint($fallback_on_x5c = false) |
|
176 | |||
177 | /** |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getX509Url() |
||
184 | |||
185 | /** |
||
186 | * @return bool |
||
187 | */ |
||
188 | protected function checkX509CertMismatch(){ |
||
192 | |||
193 | /** |
||
194 | * @param array $x5c |
||
195 | * @return $this |
||
196 | * @throws X509CertMismatchException |
||
197 | */ |
||
198 | public function setX509CertificateChain(array $x5c){ |
||
212 | } |
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.