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 |
||
14 | class Storeman |
||
15 | { |
||
16 | public const CONFIG_FILE_NAME = 'storeman.json'; |
||
17 | public const METADATA_DIRECTORY_NAME = '.storeman'; |
||
18 | |||
19 | /** |
||
20 | * @var Container |
||
21 | */ |
||
22 | protected $container; |
||
23 | |||
24 | public function __construct(Container $container = null) |
||
29 | |||
30 | /** |
||
31 | * Returns the DI container of this storeman instance. |
||
32 | * Some service names resolve to different implementations depending on the current vault which can be set as a context. |
||
33 | * E.g. "storageAdapter" resolves to the storage adapter implementation configured for the current vault. |
||
34 | * |
||
35 | * @param Vault $vault |
||
36 | * @return Container |
||
37 | */ |
||
38 | public function getContainer(Vault $vault = null): Container |
||
42 | |||
43 | /** |
||
44 | * Returns the configuration. |
||
45 | * |
||
46 | * @return Configuration |
||
47 | */ |
||
48 | public function getConfiguration(): Configuration |
||
52 | |||
53 | /** |
||
54 | * Returns a container of the configured vaults. |
||
55 | * |
||
56 | * @return VaultContainer |
||
57 | */ |
||
58 | public function getVaultContainer(): VaultContainer |
||
62 | |||
63 | /** |
||
64 | * Returns configured index builder. |
||
65 | * |
||
66 | * @return IndexBuilderInterface |
||
67 | */ |
||
68 | public function getIndexBuilder(): IndexBuilderInterface |
||
72 | |||
73 | /** |
||
74 | * @return FileReader |
||
75 | */ |
||
76 | public function getFileReader(): FileReader |
||
80 | |||
81 | /** |
||
82 | * Builds and returns an index representing the current local state. |
||
83 | * |
||
84 | * @param string $path |
||
85 | * @return Index |
||
86 | */ |
||
87 | public function getLocalIndex(string $path = null): Index |
||
94 | |||
95 | public function synchronize(array $vaultTitles = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
116 | |||
117 | public function restore(int $toRevision = null, string $fromVault = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
132 | |||
133 | public function dump(string $targetPath, int $revision = null, string $fromVault = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
148 | |||
149 | /** |
||
150 | * Returns the highest revision number across all vaults. |
||
151 | * |
||
152 | * @return int |
||
153 | */ |
||
154 | public function getLastRevision(): ?int |
||
180 | |||
181 | public function getMetadataDirectoryPath(): string |
||
185 | |||
186 | /** |
||
187 | * @param Vault[] $vaults |
||
188 | * @param string $lockName |
||
189 | */ |
||
190 | protected function acquireLocks(\Traversable $vaults, string $lockName) |
||
200 | |||
201 | /** |
||
202 | * @param Vault[] $vaults |
||
203 | * @param string $lockName |
||
204 | */ |
||
205 | protected function releaseLocks(\Traversable $vaults, string $lockName) |
||
215 | |||
216 | protected function getVaultForDownload(?int $revision, ?string $vaultTitle): ?Vault |
||
243 | |||
244 | protected function initMetadataDirectory(): string |
||
258 | |||
259 | /** |
||
260 | * @return string[] |
||
261 | */ |
||
262 | protected function getLocalIndexExclusionPatterns(): array |
||
269 | |||
270 | protected function getLogger(): LoggerInterface |
||
274 | } |
||
275 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: