Complex classes like StrictIterableTrait 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 StrictIterableTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 8 | trait StrictIterableTrait |
||
| 9 | { |
||
| 10 | use CommonMutableContainerTrait; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * {@inheritDoc} |
||
| 14 | * @return $this |
||
| 15 | */ |
||
| 16 | 1 | public function map(callable $callable) |
|
| 25 | |||
| 26 | /** |
||
| 27 | * {@inheritDoc} |
||
| 28 | * @return $this |
||
| 29 | */ |
||
| 30 | 2 | public function mapWithKey($callback) |
|
| 39 | 2 | ||
| 40 | /** |
||
| 41 | * {@inheritDoc} |
||
| 42 | 2 | * @return $this |
|
| 43 | 2 | */ |
|
| 44 | public function filter(callable $callable) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritDoc} |
||
| 58 | * @return $this |
||
| 59 | */ |
||
| 60 | public function filterWithKey($callback) |
||
| 71 | 1 | ||
| 72 | 1 | /** |
|
| 73 | * {@inheritDoc} |
||
| 74 | 1 | * @return $this |
|
| 75 | */ |
||
| 76 | 1 | public function zip(Iterable $iterable) |
|
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritDoc} |
||
| 93 | * @return $this |
||
| 94 | */ |
||
| 95 | public function take($size = 1) |
||
| 112 | |||
| 113 | public function takeWhile(callable $callable) |
||
| 125 | |||
| 126 | public function skip($n) |
||
| 139 | |||
| 140 | public function skipWhile(callable $callable) |
||
| 156 | 1 | ||
| 157 | public function slice($start, $length) |
||
| 176 | 2 | ||
| 177 | public function concat(\Traversable $iterable) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * {@inheritDoc} |
||
| 195 | * @return $this |
||
| 196 | */ |
||
| 197 | public function first() |
||
| 205 | 1 | ||
| 206 | /** |
||
| 207 | 1 | * {@inheritDoc} |
|
| 208 | * @return $this |
||
| 209 | */ |
||
| 210 | public function last() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * {@inheritDoc} |
||
| 219 | * @return $this |
||
| 220 | */ |
||
| 221 | public function each(callable $callable) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * {@inheritdoc} |
||
| 232 | */ |
||
| 233 | public function exists(callable $fn) |
||
| 243 | |||
| 244 | public function concatAll() |
||
| 256 | } |
||
| 257 |