Complex classes like StrictKeyedIterableTrait 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 StrictKeyedIterableTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | trait StrictKeyedIterableTrait |
||
| 11 | { |
||
| 12 | use CommonMutableContainerTrait; |
||
| 13 | |||
| 14 | public function keys() |
||
| 23 | |||
| 24 | public function map(callable $callback) |
||
| 33 | |||
| 34 | public function mapWithKey($callback) |
||
| 43 | |||
| 44 | public function filter(callable $callback) |
||
| 55 | |||
| 56 | public function filterWithKey($callback) |
||
| 67 | |||
| 68 | public function zip($iterable) |
||
| 82 | |||
| 83 | public function take($size = 1) |
||
| 98 | |||
| 99 | public function takeWhile($fn) |
||
| 111 | |||
| 112 | public function skip($n) |
||
| 125 | |||
| 126 | public function skipWhile($fn) |
||
| 142 | |||
| 143 | public function slice($start, $lenght) |
||
| 162 | |||
| 163 | 1 | public function concat(\Traversable $iterable) |
|
| 178 | |||
| 179 | public function first() |
||
| 187 | |||
| 188 | public function firstKey() |
||
| 196 | |||
| 197 | public function last() |
||
| 205 | |||
| 206 | public function lastKey() |
||
| 214 | |||
| 215 | /** |
||
| 216 | * {@inheritDoc} |
||
| 217 | * @return $this |
||
| 218 | */ |
||
| 219 | public function each(callable $callable) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * {@inheritdoc} |
||
| 230 | */ |
||
| 231 | public function exists(callable $fn) |
||
| 241 | |||
| 242 | public function concatAll() |
||
| 254 | } |
||
| 255 |