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 |
||
| 117 | |||
| 118 | public function restore(int $toRevision = null, string $fromVault = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
| 133 | |||
| 134 | public function dump(string $targetPath, int $revision = null, string $fromVault = null, SynchronizationProgressListenerInterface $progressListener = null): OperationResultList |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Returns the highest revision number across all vaults. |
||
| 152 | * |
||
| 153 | * @return int |
||
| 154 | */ |
||
| 155 | public function getLastRevision(): ?int |
||
| 181 | |||
| 182 | public function getMetadataDirectoryPath(): string |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param Vault[] $vaults |
||
| 189 | * @param string $lockName |
||
| 190 | */ |
||
| 191 | protected function acquireLocks(\Traversable $vaults, string $lockName) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @param Vault[] $vaults |
||
| 204 | * @param string $lockName |
||
| 205 | */ |
||
| 206 | protected function releaseLocks(\Traversable $vaults, string $lockName) |
||
| 216 | |||
| 217 | protected function getVaultForDownload(?int $revision, ?string $vaultTitle): ?Vault |
||
| 244 | |||
| 245 | protected function initMetadataDirectory(): string |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @return string[] |
||
| 262 | */ |
||
| 263 | protected function getLocalIndexExclusionPatterns(): array |
||
| 270 | |||
| 271 | protected function getLogger(): LoggerInterface |
||
| 275 | } |
||
| 276 |
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: