Complex classes like StorageTrait 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 StorageTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | trait StorageTrait |
||
9 | { |
||
10 | protected $storage; |
||
11 | |||
12 | /** |
||
13 | * Constructor. Set the storage option. |
||
14 | * |
||
15 | * @param string $storage |
||
16 | */ |
||
17 | public function __construct($storage = '') |
||
21 | |||
22 | /** |
||
23 | * Configure the storage. |
||
24 | * |
||
25 | * @param string $storage |
||
26 | * |
||
27 | * @return self |
||
28 | */ |
||
29 | public function storage($storage) |
||
35 | } |
||
36 |