Complex classes like PublicJWKSet 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 PublicJWKSet, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | final class PublicJWKSet implements JWKSetInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var int |
||
| 22 | */ |
||
| 23 | private $position = 0; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var \Jose\Object\JWKSetInterface |
||
| 27 | */ |
||
| 28 | private $jwkset; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * PublicJWKSet constructor. |
||
| 32 | * |
||
| 33 | * @param \Jose\Object\JWKSetInterface $jwkset |
||
| 34 | */ |
||
| 35 | public function __construct(JWKSetInterface $jwkset) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @inheritdoc |
||
| 42 | */ |
||
| 43 | public function current() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @inheritdoc |
||
| 50 | */ |
||
| 51 | public function next() |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @inheritdoc |
||
| 58 | */ |
||
| 59 | public function key() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @inheritdoc |
||
| 66 | */ |
||
| 67 | public function valid() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @inheritdoc |
||
| 74 | */ |
||
| 75 | public function rewind() |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @inheritdoc |
||
| 82 | */ |
||
| 83 | public function offsetExists($offset) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @inheritdoc |
||
| 90 | */ |
||
| 91 | public function offsetGet($offset) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @inheritdoc |
||
| 98 | */ |
||
| 99 | public function offsetSet($offset, $value) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @inheritdoc |
||
| 106 | */ |
||
| 107 | public function offsetUnset($offset) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * {@inheritdoc} |
||
| 114 | */ |
||
| 115 | public function hasKey($index) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | public function getKey($index) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @inheritdoc |
||
| 132 | */ |
||
| 133 | public function getKeys() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @inheritdoc |
||
| 149 | */ |
||
| 150 | public function addKey(JWKInterface $key) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @inheritdoc |
||
| 157 | */ |
||
| 158 | public function removeKey($index) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @inheritdoc |
||
| 165 | */ |
||
| 166 | public function countKeys() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @inheritdoc |
||
| 173 | */ |
||
| 174 | public function count() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @inheritdoc |
||
| 181 | */ |
||
| 182 | public function jsonSerialize() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * {@inheritdoc} |
||
| 189 | */ |
||
| 190 | public function selectKey($type, $algorithm = null, array $restrictions = []) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * @param string $type |
||
| 236 | * @param \Jose\Object\JWKInterface $key |
||
| 237 | * |
||
| 238 | * @return bool|int |
||
| 239 | */ |
||
| 240 | private function canKeyBeUsedFor($type, JWKInterface $key) |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param null|string $algorithm |
||
| 254 | * @param \Jose\Object\JWKInterface $key |
||
| 255 | * |
||
| 256 | * @return bool|int |
||
| 257 | */ |
||
| 258 | private function canKeyBeUsedWithAlgorithm($algorithm, JWKInterface $key) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param array $restrictions |
||
| 272 | * @param \Jose\Object\JWKInterface $key |
||
| 273 | * |
||
| 274 | * @return bool |
||
| 275 | */ |
||
| 276 | private function doesKeySatisfyRestrictions(array $restrictions, JWKInterface $key) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param string $key_ops |
||
| 289 | * |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | private static function convertKeyOpsToKeyUse($key_ops) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param array $a |
||
| 310 | * @param array $b |
||
| 311 | * |
||
| 312 | * @return int |
||
| 313 | */ |
||
| 314 | public function sortKeys($a, $b) |
||
| 322 | } |
||
| 323 |