Complex classes like X509Certificate often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use X509Certificate, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class X509Certificate |
||
20 | { |
||
21 | private static $typeMap = [ |
||
22 | 'RSA-SHA1' => XMLSecurityKey::RSA_SHA1, |
||
23 | 'RSA-SHA256' => XMLSecurityKey::RSA_SHA256, |
||
24 | 'RSA-SHA384' => XMLSecurityKey::RSA_SHA384, |
||
25 | 'RSA-SHA512' => XMLSecurityKey::RSA_SHA512, |
||
26 | ]; |
||
27 | |||
28 | /** @var string */ |
||
29 | protected $data; |
||
30 | |||
31 | /** @var null|array */ |
||
32 | protected $info; |
||
33 | |||
34 | /** @var string */ |
||
35 | private $signatureAlgorithm; |
||
36 | |||
37 | /** |
||
38 | * @param string $filename |
||
39 | * |
||
40 | * @return X509Certificate |
||
41 | */ |
||
42 | 33 | public static function fromFile($filename) |
|
49 | |||
50 | /** |
||
51 | * @param string $data |
||
52 | * |
||
53 | * @return X509Certificate |
||
54 | */ |
||
55 | 41 | public function setData($data) |
|
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | 85 | public function getData() |
|
70 | |||
71 | /** |
||
72 | * @param string $data |
||
73 | * |
||
74 | * @return X509Certificate |
||
75 | * |
||
76 | * @throws \InvalidArgumentException |
||
77 | */ |
||
78 | 58 | public function loadPem($data) |
|
89 | |||
90 | /** |
||
91 | * @param string $filename |
||
92 | * |
||
93 | * @return X509Certificate |
||
94 | * |
||
95 | * @throws \InvalidArgumentException |
||
96 | */ |
||
97 | 58 | public function loadFromFile($filename) |
|
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | 85 | public function toPem() |
|
117 | |||
118 | 86 | public function parse() |
|
163 | |||
164 | /** |
||
165 | * @return string |
||
166 | * |
||
167 | * @throws \LightSaml\Error\LightSamlException |
||
168 | */ |
||
169 | 24 | public function getName() |
|
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | * |
||
181 | * @throws \LightSaml\Error\LightSamlException |
||
182 | */ |
||
183 | 3 | public function getSubject() |
|
191 | |||
192 | /** |
||
193 | * @return array |
||
194 | * |
||
195 | * @throws \LightSaml\Error\LightSamlException |
||
196 | */ |
||
197 | 2 | public function getIssuer() |
|
205 | |||
206 | /** |
||
207 | * @return int |
||
208 | * |
||
209 | * @throws \LightSaml\Error\LightSamlException |
||
210 | */ |
||
211 | 2 | public function getValidFromTimestamp() |
|
219 | |||
220 | /** |
||
221 | * @return int |
||
222 | * |
||
223 | * @throws \LightSaml\Error\LightSamlException |
||
224 | */ |
||
225 | 2 | public function getValidToTimestamp() |
|
233 | |||
234 | /** |
||
235 | * @return array |
||
236 | * |
||
237 | * @throws \LightSaml\Error\LightSamlException |
||
238 | */ |
||
239 | 3 | public function getInfo() |
|
247 | |||
248 | /** |
||
249 | * @throws \LightSaml\Error\LightSamlException |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | 3 | public function getFingerprint() |
|
261 | |||
262 | 35 | public function getSignatureAlgorithm() |
|
270 | } |
||
271 |