| Conditions | 15 |
| Paths | 13 |
| Total Lines | 54 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 41 | public function validateSortAndInitializeModules(array $modules): array |
||
| 42 | { |
||
| 43 | if (empty($modules)) { |
||
| 44 | return []; |
||
| 45 | } |
||
| 46 | foreach ($modules as $identifier => $configuration) { |
||
| 47 | if (empty($configuration) || !is_array($configuration)) { |
||
| 48 | throw new InvalidConfigurationException( |
||
| 49 | 'Missing configuration for module "' . $identifier . '".', |
||
| 50 | 1519490105 |
||
| 51 | ); |
||
| 52 | } |
||
| 53 | if (!is_string($configuration['module']) || |
||
| 54 | empty($configuration['module']) || |
||
| 55 | !class_exists($configuration['module']) || |
||
| 56 | !is_subclass_of( |
||
| 57 | $configuration['module'], |
||
| 58 | ModuleInterface::class, |
||
| 59 | true |
||
| 60 | ) |
||
| 61 | ) { |
||
| 62 | throw new InvalidConfigurationException( |
||
| 63 | 'The module "' . |
||
| 64 | $identifier . |
||
| 65 | '" defines an invalid module class. Ensure the class exists and implements the "' . |
||
| 66 | ModuleInterface::class . |
||
| 67 | '".', |
||
| 68 | 1519490112 |
||
| 69 | ); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $orderedModules = GeneralUtility::makeInstance(DependencyOrderingService::class)->orderByDependencies( |
||
| 74 | $modules |
||
| 75 | ); |
||
| 76 | |||
| 77 | $moduleInstances = []; |
||
| 78 | foreach ($orderedModules as $moduleConfiguration) { |
||
| 79 | $module = GeneralUtility::makeInstance($moduleConfiguration['module']); |
||
| 80 | if ( |
||
| 81 | $module instanceof ModuleInterface |
||
| 82 | && ( |
||
| 83 | ($module instanceof ConfigurableInterface && $module->isEnabled()) |
||
| 84 | || !($module instanceof ConfigurableInterface) |
||
| 85 | ) |
||
| 86 | ) { |
||
| 87 | $moduleInstances[$module->getIdentifier()] = $module; |
||
| 88 | } |
||
| 89 | if ($module instanceof SubmoduleProviderInterface) { |
||
| 90 | $subModuleInstances = $this->validateSortAndInitializeModules($moduleConfiguration['submodules'] ?? []); |
||
| 91 | $module->setSubModules($subModuleInstances); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | return $moduleInstances; |
||
| 95 | } |
||
| 97 |