Complex classes like JWKSets 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 JWKSets, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | final class JWKSets implements JWKSetInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | private $position = 0; |
||
24 | |||
25 | /** |
||
26 | * @var \Jose\Object\JWKSetInterface[] |
||
27 | */ |
||
28 | private $jwksets = []; |
||
29 | |||
30 | /** |
||
31 | * JWKSets constructor. |
||
32 | * |
||
33 | * @param \Jose\Object\JWKSetInterface[] $jwksets |
||
34 | */ |
||
35 | public function __construct(array $jwksets) |
||
41 | |||
42 | /** |
||
43 | * PublicJWKSet constructor. |
||
44 | * |
||
45 | * @param \Jose\Object\JWKSetInterface $jwkset |
||
46 | */ |
||
47 | public function addKeySet(JWKSetInterface $jwkset) |
||
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | public function current() |
||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | */ |
||
63 | public function next() |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | public function key() |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | public function valid() |
||
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | public function rewind() |
||
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | public function offsetExists($offset) |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | public function offsetGet($offset) |
||
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | */ |
||
111 | public function offsetSet($offset, $value) |
||
115 | |||
116 | /** |
||
117 | * @inheritdoc |
||
118 | */ |
||
119 | public function offsetUnset($offset) |
||
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | public function hasKey($index) |
||
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | public function getKey($index) |
||
141 | |||
142 | /** |
||
143 | * @inheritdoc |
||
144 | */ |
||
145 | public function getKeys() |
||
158 | |||
159 | /** |
||
160 | * @inheritdoc |
||
161 | */ |
||
162 | public function addKey(JWKInterface $key) |
||
166 | |||
167 | /** |
||
168 | * @inheritdoc |
||
169 | */ |
||
170 | public function removeKey($index) |
||
174 | |||
175 | /** |
||
176 | * @inheritdoc |
||
177 | */ |
||
178 | public function countKeys() |
||
182 | |||
183 | /** |
||
184 | * @inheritdoc |
||
185 | */ |
||
186 | public function count() |
||
190 | |||
191 | /** |
||
192 | * @inheritdoc |
||
193 | */ |
||
194 | public function jsonSerialize() |
||
198 | |||
199 | /** |
||
200 | * {@inheritdoc} |
||
201 | */ |
||
202 | public function selectKey($type, $algorithm = null, array $restrictions = []) |
||
245 | |||
246 | /** |
||
247 | * @param string $type |
||
248 | * @param \Jose\Object\JWKInterface $key |
||
249 | * |
||
250 | * @return bool|int |
||
251 | */ |
||
252 | private function canKeyBeUsedFor($type, JWKInterface $key) |
||
263 | |||
264 | /** |
||
265 | * @param null|string $algorithm |
||
266 | * @param \Jose\Object\JWKInterface $key |
||
267 | * |
||
268 | * @return bool|int |
||
269 | */ |
||
270 | private function canKeyBeUsedWithAlgorithm($algorithm, JWKInterface $key) |
||
281 | |||
282 | /** |
||
283 | * @param array $restrictions |
||
284 | * @param \Jose\Object\JWKInterface $key |
||
285 | * |
||
286 | * @return bool |
||
287 | */ |
||
288 | private function doesKeySatisfyRestrictions(array $restrictions, JWKInterface $key) |
||
298 | |||
299 | /** |
||
300 | * @param string $key_ops |
||
301 | * |
||
302 | * @return string |
||
303 | */ |
||
304 | private static function convertKeyOpsToKeyUse($key_ops) |
||
319 | |||
320 | /** |
||
321 | * @param array $a |
||
322 | * @param array $b |
||
323 | * |
||
324 | * @return int |
||
325 | */ |
||
326 | public function sortKeys($a, $b) |
||
334 | } |
||
335 |