Complex classes like Loader 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 Loader, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | final class Loader implements LoaderInterface |
||
27 | { |
||
28 | /** |
||
29 | * Loader constructor. |
||
30 | */ |
||
31 | private function __construct() |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public static function load($input) |
||
49 | |||
50 | /** |
||
51 | * @param array $data |
||
52 | * |
||
53 | * @return \Jose\Object\JWSInterface |
||
54 | */ |
||
55 | private static function loadSerializedJsonJWS(array $data) |
||
82 | |||
83 | /** |
||
84 | * @param array $data |
||
85 | * |
||
86 | * @return \Jose\Object\JWEInterface |
||
87 | */ |
||
88 | private static function loadSerializedJsonJWE(array $data) |
||
109 | |||
110 | /** |
||
111 | * @param \Jose\Object\JWEInterface $jwe |
||
112 | * @param array $data |
||
113 | */ |
||
114 | private static function populateIV(JWEInterface &$jwe, array $data) |
||
120 | |||
121 | /** |
||
122 | * @param \Jose\Object\JWEInterface $jwe |
||
123 | * @param array $data |
||
124 | */ |
||
125 | private static function populateAAD(JWEInterface &$jwe, array $data) |
||
131 | |||
132 | /** |
||
133 | * @param \Jose\Object\JWEInterface $jwe |
||
134 | * @param array $data |
||
135 | */ |
||
136 | private static function populateTag(JWEInterface &$jwe, array $data) |
||
142 | |||
143 | /** |
||
144 | * @param \Jose\Object\JWEInterface $jwe |
||
145 | * @param array $data |
||
146 | */ |
||
147 | private static function populateSharedProtectedHeaders(JWEInterface &$jwe, array $data) |
||
154 | |||
155 | /** |
||
156 | * @param \Jose\Object\JWEInterface $jwe |
||
157 | * @param array $data |
||
158 | */ |
||
159 | private static function populateSharedHeaders(JWEInterface &$jwe, array $data) |
||
165 | |||
166 | /** |
||
167 | * @param \Jose\Object\RecipientInterface $recipient |
||
168 | * @param array $data |
||
169 | */ |
||
170 | private static function populateRecipientHeaders(RecipientInterface &$recipient, array $data) |
||
176 | |||
177 | /** |
||
178 | * @param \Jose\Object\RecipientInterface $recipient |
||
179 | * @param array $data |
||
180 | */ |
||
181 | private static function populateRecipientEncryptedKey(RecipientInterface &$recipient, array $data) |
||
187 | |||
188 | /** |
||
189 | * @param string $input |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | private static function convert($input) |
||
208 | |||
209 | /** |
||
210 | * @param $input |
||
211 | * |
||
212 | * @return array |
||
213 | */ |
||
214 | private static function fromFlattenedSerializationRecipientToSerialization($input) |
||
234 | |||
235 | /** |
||
236 | * @param $input |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | private static function fromFlattenedSerializationSignatureToSerialization($input) |
||
259 | |||
260 | /** |
||
261 | * @param string $input |
||
262 | * |
||
263 | * @return array |
||
264 | */ |
||
265 | private static function fromCompactSerializationToSerialization($input) |
||
277 | |||
278 | /** |
||
279 | * @param array $parts |
||
280 | * |
||
281 | * @return array |
||
282 | */ |
||
283 | private static function fromCompactSerializationRecipientToSerialization(array $parts) |
||
301 | |||
302 | /** |
||
303 | * @param array $parts |
||
304 | * |
||
305 | * @return array |
||
306 | */ |
||
307 | private static function fromCompactSerializationSignatureToSerialization(array $parts) |
||
321 | } |
||
322 |