| Conditions | 7 |
| Paths | 22 |
| Total Lines | 51 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 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 |
||
| 100 | public function load(ConfigurationInterface $configuration) |
||
| 101 | { |
||
| 102 | |||
| 103 | // load the DI container, vendor and custom configuration |
||
| 104 | // directory as well as the Magento version |
||
| 105 | $container = $this->getContainer(); |
||
| 106 | $vendorDir = $this->getVendorDir(); |
||
| 107 | $magentoVersion = $configuration->getMagentoVersion(); |
||
| 108 | $customConfigurationDir = $this->getCustomConfigurationDir(); |
||
| 109 | |||
| 110 | // initialize the default loader and load the DI configuration for the this library |
||
| 111 | $defaultLoader = new XmlFileLoader($container, new FileLocator($vendorDir)); |
||
| 112 | |||
| 113 | // load the DI configuration for all the extension libraries |
||
| 114 | foreach ($configuration->getExtensionLibraries() as $library) { |
||
| 115 | $this->loadConfiguration($defaultLoader, $magentoVersion, sprintf('%s/%s', $vendorDir, $library)); |
||
| 116 | } |
||
| 117 | |||
| 118 | // register autoloaders for additional vendor directories |
||
| 119 | $customLoader = new XmlFileLoader($container, new FileLocator()); |
||
| 120 | foreach ($configuration->getAdditionalVendorDirs() as $additionalVendorDir) { |
||
| 121 | // try to load the vendor directory's auto loader, if available. Otherwise we assume |
||
| 122 | // that the vendor directory uses an autoloader that has already been loaded, e. g. in |
||
| 123 | // case of Magento which has app/code registered as vendor directory what we want to use |
||
| 124 | if (file_exists($autoLoader = $additionalVendorDir->getVendorDir() . '/autoload.php')) { |
||
| 125 | require $autoLoader; |
||
| 126 | } |
||
| 127 | |||
| 128 | // try to load the DI configuration for the configured extension libraries |
||
| 129 | foreach ($additionalVendorDir->getLibraries() as $library) { |
||
| 130 | // concatenate the directory for the library |
||
| 131 | $libDir = sprintf('%s/%s', $additionalVendorDir->getVendorDir(), $library); |
||
| 132 | // prepend the installation directory, if the vendor is relative to it |
||
| 133 | if ($additionalVendorDir->isRelative()) { |
||
| 134 | $libDir = sprintf('%s/%s', $configuration->getInstallationDir(), $libDir); |
||
| 135 | } |
||
| 136 | |||
| 137 | // create the canonicalized absolute pathname and try to load the configuration |
||
| 138 | if ($libraryDir = realpath($libDir)) { |
||
| 139 | $this->loadConfiguration($customLoader, $magentoVersion, $libraryDir); |
||
| 140 | } else { |
||
| 141 | throw new \Exception(sprintf('Can\'t find find library directory "%s"', $libDir)); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | // initialize the project specific configuration loader for the DI configuration |
||
| 147 | $projectLoader = new XmlFileLoader($container, new FileLocator(getcwd())); |
||
| 148 | |||
| 149 | // finally load the project specific custom library configuration which overwrites the default one |
||
| 150 | $this->loadConfiguration($projectLoader, $magentoVersion, $customConfigurationDir); |
||
| 151 | } |
||
| 207 |