Complex classes like BaseJWKSet 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 BaseJWKSet, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | trait BaseJWKSet |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var int |
||
| 23 | */ |
||
| 24 | private $position = 0; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param int $index |
||
| 28 | * |
||
| 29 | * @return bool |
||
| 30 | */ |
||
| 31 | public function hasKey($index) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param int $index |
||
| 38 | * |
||
| 39 | * @return \Jose\Object\JWKInterface |
||
| 40 | */ |
||
| 41 | public function getKey($index) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return \Jose\Object\JWKInterface[] |
||
| 52 | */ |
||
| 53 | abstract public function getKeys(); |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param \Jose\Object\JWKInterface $key |
||
| 57 | */ |
||
| 58 | abstract public function addKey(JWKInterface $key); |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param int $index |
||
| 62 | */ |
||
| 63 | abstract public function removeKey($index); |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return array |
||
| 67 | */ |
||
| 68 | public function jsonSerialize() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param int $mode |
||
| 75 | * |
||
| 76 | * @return int |
||
| 77 | */ |
||
| 78 | public function count($mode = COUNT_NORMAL) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return \Jose\Object\JWKInterface|null |
||
| 85 | */ |
||
| 86 | public function current() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return int |
||
| 93 | */ |
||
| 94 | public function key() |
||
| 98 | |||
| 99 | public function next() |
||
| 103 | |||
| 104 | public function rewind() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return bool |
||
| 111 | */ |
||
| 112 | public function valid() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return int |
||
| 119 | */ |
||
| 120 | public function countKeys() |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @param mixed $offset |
||
| 127 | * |
||
| 128 | * @return bool |
||
| 129 | */ |
||
| 130 | public function offsetExists($offset) |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param mixed $offset |
||
| 137 | * |
||
| 138 | * @return \Jose\Object\JWKInterface |
||
| 139 | */ |
||
| 140 | public function offsetGet($offset) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * @param mixed $offset |
||
| 147 | * @param mixed $value |
||
| 148 | */ |
||
| 149 | public function offsetSet($offset, $value) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param int $offset |
||
| 156 | */ |
||
| 157 | public function offsetUnset($offset) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param string $type |
||
| 164 | * @param null|string $algorithm |
||
| 165 | * @param array $restrictions |
||
| 166 | * |
||
| 167 | * @return null|\Jose\Object\JWKInterface |
||
| 168 | */ |
||
| 169 | public function selectKey($type, $algorithm = null, array $restrictions = []) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param string $type |
||
| 214 | * @param \Jose\Object\JWKInterface $key |
||
| 215 | * |
||
| 216 | * @return bool|int |
||
| 217 | */ |
||
| 218 | private function canKeyBeUsedFor($type, JWKInterface $key) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @param null|string $algorithm |
||
| 232 | * @param \Jose\Object\JWKInterface $key |
||
| 233 | * |
||
| 234 | * @return bool|int |
||
| 235 | */ |
||
| 236 | private function canKeyBeUsedWithAlgorithm($algorithm, JWKInterface $key) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @param array $restrictions |
||
| 250 | * @param \Jose\Object\JWKInterface $key |
||
| 251 | * |
||
| 252 | * @return bool |
||
| 253 | */ |
||
| 254 | private function doesKeySatisfyRestrictions(array $restrictions, JWKInterface $key) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param string $key_ops |
||
| 267 | * |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | private static function convertKeyOpsToKeyUse($key_ops) |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param array $a |
||
| 288 | * @param array $b |
||
| 289 | * |
||
| 290 | * @return int |
||
| 291 | */ |
||
| 292 | public function sortKeys($a, $b) |
||
| 300 | } |
||
| 301 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.