| Conditions | 13 |
| Paths | 194 |
| Total Lines | 103 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| 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 |
||
| 47 | public function load() |
||
| 48 | { |
||
| 49 | |||
| 50 | // load the configuration instance |
||
| 51 | $instance = parent::load(); |
||
| 52 | |||
| 53 | // query whether or not a shortcut has been specified as command line |
||
| 54 | // argument, if yes override the value from the configuration file |
||
| 55 | if ($this->input->hasArgument(InputArgumentKeysInterface::SHORTCUT)) { |
||
| 56 | $instance->setShortcut($this->input->getArgument(InputArgumentKeysInterface::SHORTCUT)); |
||
| 57 | } |
||
| 58 | |||
| 59 | // query whether or not an explicit filename has been specified as command |
||
| 60 | // line argument, if yes override the value from the configuration file |
||
| 61 | if ($this->input->hasArgument(InputArgumentKeysInterface::FILENAME) && |
||
|
|
|||
| 62 | $filename = $this->input->getArgument(InputArgumentKeysInterface::FILENAME) |
||
| 63 | ) { |
||
| 64 | // try to load the realpath of the given filename |
||
| 65 | $filename = realpath($filename); |
||
| 66 | // query whether or not the file is available |
||
| 67 | if (is_file($filename)) { |
||
| 68 | // set the filename in the configuration |
||
| 69 | $instance->setFilename($filename); |
||
| 70 | // AND update the source directory to the directory |
||
| 71 | // where the specified file has been sourced |
||
| 72 | $instance->setSourceDir(dirname($filename)); |
||
| 73 | } else { |
||
| 74 | throw new \InvalidArgumentException( |
||
| 75 | sprintf('Can\'t find file "%s" that has to be imported', $this->input->getArgument(InputArgumentKeysInterface::FILENAME)) |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | // query whether or not operation names has been specified as command line |
||
| 81 | // option, if yes override the value from the configuration file |
||
| 82 | if ($this->input->hasArgument(InputArgumentKeysInterface::OPERATION_NAMES)) { |
||
| 83 | // load the operation names from the commandline |
||
| 84 | $operationNames = $this->input->getArgument(InputArgumentKeysInterface::OPERATION_NAMES); |
||
| 85 | // append the names of the operations we want to execute to the configuration |
||
| 86 | foreach ($operationNames as $operationName) { |
||
| 87 | $instance->addOperationName($operationName); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | // query whether or not we've an valid Magento root directory specified |
||
| 92 | if ($this->isMagentoRootDir($installationDir = $instance->getInstallationDir())) { |
||
| 93 | // if yes, add the database configuration |
||
| 94 | $instance->addDatabase($this->getMagentoDbConnection($installationDir)); |
||
| 95 | } |
||
| 96 | |||
| 97 | // query whether or not a DB ID has been specified as command line |
||
| 98 | // option, if yes override the value from the configuration file |
||
| 99 | if ($useDbId = $this->input->getOption(InputOptionKeysInterface::USE_DB_ID)) { |
||
| 100 | $instance->setUseDbId($useDbId); |
||
| 101 | } else { |
||
| 102 | // query whether or not a PDO DSN has been specified as command line |
||
| 103 | // option, if yes override the value from the configuration file |
||
| 104 | if ($dsn = $this->input->getOption(InputOptionKeysInterface::DB_PDO_DSN)) { |
||
| 105 | // first REMOVE all other database configurations |
||
| 106 | $instance->clearDatabases(); |
||
| 107 | |||
| 108 | // add the database configuration |
||
| 109 | $instance->addDatabase( |
||
| 110 | $this->newDatabaseConfiguration( |
||
| 111 | $dsn, |
||
| 112 | $this->input->getOption(InputOptionKeysInterface::DB_USERNAME), |
||
| 113 | $this->input->getOption(InputOptionKeysInterface::DB_PASSWORD) |
||
| 114 | ) |
||
| 115 | ); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | // query whether or not a DB ID has been specified as command line |
||
| 120 | // option, if yes override the value from the configuration file |
||
| 121 | if ($tablePrefix = $this->input->getOption(InputOptionKeysInterface::DB_TABLE_PREFIX)) { |
||
| 122 | $instance->getDatabase()->setTablePrefix($tablePrefix); |
||
| 123 | } |
||
| 124 | |||
| 125 | // query whether or not the debug mode is enabled and log level |
||
| 126 | // has NOT been overwritten with a commandline option |
||
| 127 | if ($instance->isDebugMode() && !$this->input->getOption(InputOptionKeysInterface::LOG_LEVEL)) { |
||
| 128 | // set debug log level, if log level has NOT been overwritten on command line |
||
| 129 | $instance->setLogLevel(LogLevel::DEBUG); |
||
| 130 | } |
||
| 131 | |||
| 132 | // prepend the array with the Magento Edition specific core libraries |
||
| 133 | $instance->setExtensionLibraries( |
||
| 134 | array_merge( |
||
| 135 | $this->getDefaultLibrariesByMagentoEdition($instance->getMagentoEdition()), |
||
| 136 | $instance->getExtensionLibraries() |
||
| 137 | ) |
||
| 138 | ); |
||
| 139 | |||
| 140 | // load the extension libraries, if configured |
||
| 141 | $this->libraryLoader->load($instance); |
||
| 142 | |||
| 143 | // register the configured aliases in the DI container, this MUST |
||
| 144 | // happen after the libraries have been loaded, else it would not |
||
| 145 | // be possible to override existing aliases |
||
| 146 | $this->initializeAliases($instance); |
||
| 147 | |||
| 148 | // return the initialized configuration instance |
||
| 149 | return $instance; |
||
| 150 | } |
||
| 299 |