| Conditions | 21 |
| Paths | 99 |
| Total Lines | 104 |
| Code Lines | 44 |
| Lines | 15 |
| Ratio | 14.42 % |
| 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 |
||
| 160 | public function load() |
||
| 161 | { |
||
| 162 | |||
| 163 | // load the actual vendor directory and entity type code |
||
| 164 | $vendorDir = $this->getVendorDir(); |
||
| 165 | |||
| 166 | // the path of the JMS serializer directory, relative to the vendor directory |
||
| 167 | $jmsDir = DIRECTORY_SEPARATOR . 'jms' . DIRECTORY_SEPARATOR . 'serializer' . DIRECTORY_SEPARATOR . 'src'; |
||
| 168 | |||
| 169 | // try to find the path to the JMS Serializer annotations |
||
| 170 | if (!file_exists($annotationDir = $vendorDir . DIRECTORY_SEPARATOR . $jmsDir)) { |
||
| 171 | // stop processing, if the JMS annotations can't be found |
||
| 172 | throw new \Exception( |
||
| 173 | sprintf( |
||
| 174 | 'The jms/serializer libarary can not be found in one of "%s"', |
||
| 175 | implode(', ', $vendorDir) |
||
| 176 | ) |
||
| 177 | ); |
||
| 178 | } |
||
| 179 | |||
| 180 | // register the autoloader for the JMS serializer annotations |
||
| 181 | \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace( |
||
| 182 | 'JMS\Serializer\Annotation', |
||
| 183 | $annotationDir |
||
| 184 | ); |
||
| 185 | |||
| 186 | // query whether or not, a configuration file has been specified |
||
| 187 | if ($configuration = $this->input->getOption(InputOptionKeys::CONFIGURATION)) { |
||
| 188 | // load the configuration from the file with the given filename |
||
| 189 | $instance = $this->configurationFactory->factory($configuration); |
||
| 190 | |||
|
|
|||
| 191 | } elseif ($magentoEdition = $this->input->getOption(InputOptionKeys::MAGENTO_EDITION)) { |
||
| 192 | // use the Magento Edition that has been specified as option |
||
| 193 | $instance = $this->configurationFactory->factory($this->getDefaultConfiguration($magentoEdition, $this->getEntityTypeCode())); |
||
| 194 | |||
| 195 | // override the Magento Edition |
||
| 196 | $instance->setMagentoEdition($magentoEdition); |
||
| 197 | |||
| 198 | } else { |
||
| 199 | // finally, query whether or not the installation directory is a valid Magento root directory |
||
| 200 | if (!$this->isMagentoRootDir($installationDir = $this->input->getOption(InputOptionKeys::INSTALLATION_DIR))) { |
||
| 201 | throw new \Exception( |
||
| 202 | sprintf( |
||
| 203 | 'Directory "%s" specified with option "--installation-dir" is not a valid Magento root directory', |
||
| 204 | $installationDir |
||
| 205 | ) |
||
| 206 | ); |
||
| 207 | } |
||
| 208 | |||
| 209 | // load the composer file from the Magento root directory |
||
| 210 | $composer = json_decode(file_get_contents($composerFile = sprintf('%s/composer.json', $installationDir)), true); |
||
| 211 | |||
| 212 | // try to load and explode the Magento Edition identifier from the Composer name |
||
| 213 | $explodedVersion = explode('/', $composer[MagentoConfigurationKeys::COMPOSER_EDITION_NAME_ATTRIBUTE]); |
||
| 214 | |||
| 215 | // try to locate Magento Edition |
||
| 216 | if (!isset($this->editionMappings[$possibleEdition = end($explodedVersion)])) { |
||
| 217 | throw new \Exception( |
||
| 218 | sprintf( |
||
| 219 | '"%s" detected in "%s" is not a valid Magento Edition, please set Magento Edition with the "--magento-edition" option', |
||
| 220 | $possibleEdition, |
||
| 221 | $composerFile |
||
| 222 | ) |
||
| 223 | ); |
||
| 224 | } |
||
| 225 | |||
| 226 | // if Magento Edition/Version are available, load them |
||
| 227 | $magentoEdition = $this->editionMappings[$possibleEdition]; |
||
| 228 | |||
| 229 | // use the Magento Edition that has been detected by the installation directory |
||
| 230 | $instance = $this->configurationFactory->factory($this->getDefaultConfiguration($magentoEdition, $this->getEntityTypeCode())); |
||
| 231 | |||
| 232 | // override the Magento Edition, if NOT explicitly specified |
||
| 233 | $instance->setMagentoEdition($magentoEdition); |
||
| 234 | } |
||
| 235 | |||
| 236 | // query whether or not a system name has been specified as command line option, if yes override the value from the configuration file |
||
| 237 | View Code Duplication | if (($this->input->hasOptionSpecified(InputOptionKeys::SYSTEM_NAME) && $this->input->getOption(InputOptionKeys::SYSTEM_NAME)) || $instance->getSystemName() === null) { |
|
| 238 | $instance->setSystemName($this->input->getOption(InputOptionKeys::SYSTEM_NAME)); |
||
| 239 | } |
||
| 240 | |||
| 241 | // query whether or not a PID filename has been specified as command line option, if yes override the value from the configuration file |
||
| 242 | View Code Duplication | if (($this->input->hasOptionSpecified(InputOptionKeys::PID_FILENAME) && $this->input->getOption(InputOptionKeys::PID_FILENAME)) || $instance->getPidFilename() === null) { |
|
| 243 | $instance->setPidFilename($this->input->getOption(InputOptionKeys::PID_FILENAME)); |
||
| 244 | } |
||
| 245 | |||
| 246 | // query whether or not a Magento installation directory has been specified as command line option, if yes override the value from the configuration file |
||
| 247 | View Code Duplication | if (($this->input->hasOptionSpecified(InputOptionKeys::INSTALLATION_DIR) && $this->input->getOption(InputOptionKeys::INSTALLATION_DIR)) || $instance->getInstallationDir() === null) { |
|
| 248 | $instance->setInstallationDir($this->input->getOption(InputOptionKeys::INSTALLATION_DIR)); |
||
| 249 | } |
||
| 250 | |||
| 251 | // query whether or not a Magento edition has been specified as command line option, if yes override the value from the configuration file |
||
| 252 | View Code Duplication | if (($this->input->hasOptionSpecified(InputOptionKeys::MAGENTO_EDITION) && $this->input->getOption(InputOptionKeys::MAGENTO_EDITION)) || $instance->getMagentoEdition() === null) { |
|
| 253 | $instance->setMagentoEdition($this->input->getOption(InputOptionKeys::MAGENTO_EDITION)); |
||
| 254 | } |
||
| 255 | |||
| 256 | // query whether or not a directory for the source files has been specified as command line option, if yes override the value from the configuration file |
||
| 257 | View Code Duplication | if (($this->input->hasOptionSpecified(InputOptionKeys::SOURCE_DIR) && $this->input->getOption(InputOptionKeys::SOURCE_DIR)) || $instance->getSourceDir() === null) { |
|
| 258 | $instance->setSourceDir($this->input->getOption(InputOptionKeys::SOURCE_DIR)); |
||
| 259 | } |
||
| 260 | |||
| 261 | // return the initialized configuration instance |
||
| 262 | return $instance; |
||
| 263 | } |
||
| 264 | |||
| 372 |