Complex classes like Container 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 Container, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | final class Container implements ContainerInterface |
||
| 35 | { |
||
| 36 | protected const PREFIX_CONFLICT_HANDLER = 'conflictHandler.'; |
||
| 37 | protected const PREFIX_INDEX_BUILDER = 'indexBuilder.'; |
||
| 38 | protected const PREFIX_INDEX_MERGER = 'indexMerger.'; |
||
| 39 | protected const PREFIX_LOCK_ADAPTER = 'lockAdapter.'; |
||
| 40 | protected const PREFIX_OPERATION_LIST_BUILDER = 'operationListBuilder.'; |
||
| 41 | protected const PREFIX_STORAGE_ADAPTER = 'storageAdapter.'; |
||
| 42 | protected const PREFIX_VAULT_LAYOUT = 'vaultLayout.'; |
||
| 43 | |||
| 44 | |||
| 45 | /** |
||
| 46 | * @var InspectableContainer |
||
| 47 | */ |
||
| 48 | protected $delegate; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Sets up the container with all bundled services. |
||
| 52 | * |
||
| 53 | * Note: Be very careful with shared services as the container is used shared by all vaults of a storeman instance. |
||
| 54 | */ |
||
| 55 | public function __construct() |
||
| 91 | |||
| 92 | public function injectConfiguration(Configuration $configuration): Container |
||
| 103 | |||
| 104 | public function injectStoreman(Storeman $storeman): Container |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Selects the given vault (or no vault) as the current one. |
||
| 118 | * |
||
| 119 | * @param Vault $vault |
||
| 120 | * @return Container |
||
| 121 | */ |
||
| 122 | public function selectVault(Vault $vault = null): Container |
||
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | public function get($id) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | */ |
||
| 140 | public function has($id) |
||
| 144 | |||
| 145 | |||
| 146 | public function getStoreman(): Storeman |
||
| 150 | |||
| 151 | public function getConfiguration(): Configuration |
||
| 155 | |||
| 156 | public function getVaultContainer(): VaultContainer |
||
| 160 | |||
| 161 | public function getSelectedVault(): ?Vault |
||
| 165 | |||
| 166 | |||
| 167 | public function getLogger(): LoggerInterface |
||
| 171 | |||
| 172 | public function setLogger(LoggerInterface $logger): Container |
||
| 178 | |||
| 179 | |||
| 180 | public function getConflictHandler(string $name): ConflictHandlerInterface |
||
| 184 | |||
| 185 | public function addConflictHandler(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 189 | |||
| 190 | public function getConflictHandlerNames(): array |
||
| 194 | |||
| 195 | |||
| 196 | public function getIndexMerger(string $name): IndexMergerInterface |
||
| 200 | |||
| 201 | public function addIndexMerger(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 205 | |||
| 206 | public function getIndexMergerNames(): array |
||
| 210 | |||
| 211 | |||
| 212 | public function getIndexBuilder(string $name): IndexBuilderInterface |
||
| 216 | |||
| 217 | public function addIndexBuilder(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 221 | |||
| 222 | public function getIndexBuilderNames(): array |
||
| 226 | |||
| 227 | |||
| 228 | public function getLockAdapter(string $name): LockAdapterInterface |
||
| 232 | |||
| 233 | public function addLockAdapter(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 237 | |||
| 238 | public function getLockAdapterNames(): array |
||
| 242 | |||
| 243 | |||
| 244 | public function getOperationListBuilder(string $name): OperationListBuilderInterface |
||
| 248 | |||
| 249 | public function addOperationListBuilder(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 253 | |||
| 254 | public function getOperationListBuilderNames(): array |
||
| 258 | |||
| 259 | |||
| 260 | public function getStorageAdapter(string $name): StorageAdapterInterface |
||
| 264 | |||
| 265 | public function addStorageAdapter(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 269 | |||
| 270 | public function getStorageAdapterNames(): array |
||
| 274 | |||
| 275 | |||
| 276 | public function getVaultLayout(string $name): VaultLayoutInterface |
||
| 280 | |||
| 281 | public function addVaultLayout(string $name, $concrete, bool $shared = false): DefinitionInterface |
||
| 285 | |||
| 286 | public function getVaultLayoutNames(): array |
||
| 290 | |||
| 291 | |||
| 292 | protected function getConflictHandlerServiceName(string $name): string |
||
| 296 | |||
| 297 | protected function getIndexBuilderServiceName(string $name): string |
||
| 301 | |||
| 302 | protected function getIndexMergerServiceName(string $name): string |
||
| 306 | |||
| 307 | protected function getLockAdapterServiceName(string $name): string |
||
| 311 | |||
| 312 | protected function getOperationListBuilderServiceName(string $name): string |
||
| 316 | |||
| 317 | protected function getStorageAdapterServiceName(string $name): string |
||
| 321 | |||
| 322 | protected function getVaultLayoutServiceName(string $name): string |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Registers a factory for a type of service. |
||
| 329 | * |
||
| 330 | * @param string $type |
||
| 331 | * @param string $configurationKey |
||
| 332 | */ |
||
| 333 | protected function registerServiceFactory(string $type, string $configurationKey = null): void |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Registers a factory for a type of vault-specific module. |
||
| 352 | * |
||
| 353 | * @param string $type |
||
| 354 | * @param string $vaultConfigurationKey |
||
| 355 | */ |
||
| 356 | protected function registerVaultServiceFactory(string $type, string $vaultConfigurationKey = null): void |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Builds and returns list of added service names starting with a given prefix. |
||
| 375 | * |
||
| 376 | * @param string $prefix |
||
| 377 | * @return string[] |
||
| 378 | */ |
||
| 379 | protected function getServiceNamesWithPrefix(string $prefix): array |
||
| 400 | } |
||
| 401 |
It seems like you are assigning to a variable which was imported through a
usestatement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope