Complex classes like Storeman 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 Storeman, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | class Storeman |
||
12 | { |
||
13 | /** |
||
14 | * @var Container |
||
15 | */ |
||
16 | protected $container; |
||
17 | |||
18 | public function __construct(Container $container = null) |
||
23 | |||
24 | public function getConfiguration(): Configuration |
||
28 | |||
29 | /** |
||
30 | * Returns the DI container of this storeman instance. |
||
31 | * Some service names resolve to different implementations depending on the current vault which can be set as a context. |
||
32 | * E.g. "storageAdapter" resolves to the storage adapter implementation configured for the current vault. |
||
33 | * |
||
34 | * @param Vault $vault |
||
35 | * @return Container |
||
36 | */ |
||
37 | public function getContainer(Vault $vault = null): Container |
||
41 | |||
42 | /** |
||
43 | * Returns a specific vault by title. |
||
44 | * |
||
45 | * @param string $vaultTitle |
||
46 | * @return Vault |
||
47 | */ |
||
48 | public function getVault(string $vaultTitle): Vault |
||
61 | |||
62 | /** |
||
63 | * Returns all configured vaults. |
||
64 | * |
||
65 | * @return Vault[] |
||
66 | */ |
||
67 | public function getVaults(): array |
||
75 | |||
76 | /** |
||
77 | * Returns a subset of the configured vaults identified by the given set of titles. |
||
78 | * |
||
79 | * @param array $titles |
||
80 | * @return Vault[] |
||
81 | */ |
||
82 | public function getVaultsByTitle(array $titles): array |
||
89 | |||
90 | /** |
||
91 | * Returns all those vaults that have a given revision. |
||
92 | * |
||
93 | * @param int $revision |
||
94 | * @return Vault[] |
||
95 | */ |
||
96 | public function getVaultsHavingRevision(int $revision): array |
||
103 | |||
104 | /** |
||
105 | * Returns the vault with the highest priority. |
||
106 | * |
||
107 | * @param Vault[] $vaults Vaults to consider. Defaults to all configured vaults. |
||
108 | * @return Vault |
||
109 | */ |
||
110 | public function getPrioritizedVault(array $vaults = null): ?Vault |
||
127 | |||
128 | public function synchronize(array $vaultTitles = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
146 | |||
147 | public function restore(int $toRevision = null, string $fromVault = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
160 | |||
161 | public function dump(string $targetPath, int $revision = null, string $fromVault = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
174 | |||
175 | /** |
||
176 | * Returns the highest revision number across all vaults. |
||
177 | * |
||
178 | * @return int |
||
179 | */ |
||
180 | public function getLastRevision(): ?int |
||
194 | |||
195 | /** |
||
196 | * Builds and returns a history of all synchronizations on record for this archive. |
||
197 | * |
||
198 | * @return Synchronization[][] |
||
199 | */ |
||
200 | public function buildSynchronizationHistory(): array |
||
221 | |||
222 | /** |
||
223 | * @param Vault[] $vaults |
||
224 | * @param string $lockName |
||
225 | */ |
||
226 | protected function acquireLocks(array $vaults, string $lockName) |
||
236 | |||
237 | /** |
||
238 | * @param Vault[] $vaults |
||
239 | * @param string $lockName |
||
240 | */ |
||
241 | protected function releaseLocks(array $vaults, string $lockName) |
||
251 | |||
252 | protected function getVaultForDownload(?int $revision, ?string $vaultTitle): ?Vault |
||
277 | } |
||
278 |