| Conditions | 20 |
| Paths | > 20000 |
| Total Lines | 127 |
| Code Lines | 44 |
| 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 |
||
| 53 | public static function load(InputInterface $input) |
||
| 54 | { |
||
| 55 | |||
| 56 | // load the configuration from the file with the given filename |
||
| 57 | $instance = static::factory($input->getOption(InputOptionKeys::CONFIGURATION)); |
||
| 58 | |||
| 59 | // query whether or not an operation name has been specified as command line |
||
| 60 | // option, if yes override the value from the configuration file |
||
| 61 | if ($operationName = $input->getArgument(InputArgumentKeys::OPERATION_NAME)) { |
||
| 62 | $instance->setOperationName($operationName); |
||
| 63 | } |
||
| 64 | |||
| 65 | // query whether or not a Magento installation directory has been specified as command line |
||
| 66 | // option, if yes override the value from the configuration file |
||
| 67 | if ($installationDir = $input->getOption(InputOptionKeys::INSTALLATION_DIR)) { |
||
| 68 | $instance->setInstallationDir($installationDir); |
||
| 69 | } |
||
| 70 | |||
| 71 | // query whether or not a directory for the source files has been specified as command line |
||
| 72 | // option, if yes override the value from the configuration file |
||
| 73 | if ($sourceDir = $input->getOption(InputOptionKeys::SOURCE_DIR)) { |
||
| 74 | $instance->setSourceDir($sourceDir); |
||
| 75 | } |
||
| 76 | |||
| 77 | // query whether or not a directory containing the imported files has been specified as command line |
||
| 78 | // option, if yes override the value from the configuration file |
||
| 79 | if ($targetDir = $input->getOption(InputOptionKeys::TARGET_DIR)) { |
||
| 80 | $instance->setTargetDir($targetDir); |
||
| 81 | } |
||
| 82 | |||
| 83 | // query whether or not a source date format has been specified as command |
||
| 84 | // line option, if yes override the value from the configuration file |
||
| 85 | if ($sourceDateFormat = $input->getOption(InputOptionKeys::SOURCE_DATE_FORMAT)) { |
||
| 86 | $instance->setSourceDateFormat($sourceDateFormat); |
||
| 87 | } |
||
| 88 | |||
| 89 | // query whether or not a Magento edition has been specified as command line |
||
| 90 | // option, if yes override the value from the configuration file |
||
| 91 | if ($magentoEdition = $input->getOption(InputOptionKeys::MAGENTO_EDITION)) { |
||
| 92 | $instance->setMagentoEdition($magentoEdition); |
||
| 93 | } |
||
| 94 | |||
| 95 | // query whether or not a Magento version has been specified as command line |
||
| 96 | // option, if yes override the value from the configuration file |
||
| 97 | if ($magentoVersion = $input->getOption(InputOptionKeys::MAGENTO_VERSION)) { |
||
| 98 | $instance->setMagentoVersion($magentoVersion); |
||
| 99 | } |
||
| 100 | |||
| 101 | // query whether or not a DB ID has been specified as command line |
||
| 102 | // option, if yes override the value from the configuration file |
||
| 103 | if ($useDbId = $input->getOption(InputOptionKeys::USE_DB_ID)) { |
||
| 104 | $instance->setUseDbId($useDbId); |
||
| 105 | } else { |
||
| 106 | // query whether or not a PDO DSN has been specified as command line |
||
| 107 | // option, if yes override the value from the configuration file |
||
| 108 | if ($dsn = $input->getOption(InputOptionKeys::DB_PDO_DSN)) { |
||
| 109 | // first REMOVE all other database configurations |
||
| 110 | $instance->clearDatabases(); |
||
| 111 | |||
| 112 | // initialize a new database configuration |
||
| 113 | $database = new Database(); |
||
| 114 | $database->setId(Uuid::uuid4()->__toString()); |
||
| 115 | $database->setDefault(true); |
||
| 116 | $database->setDsn($dsn); |
||
| 117 | |||
| 118 | // query whether or not a DB username has been specified as command line |
||
| 119 | // option, if yes override the value from the configuration file |
||
| 120 | if ($username = $input->getOption(InputOptionKeys::DB_USERNAME)) { |
||
| 121 | $database->setUsername($username); |
||
| 122 | } |
||
| 123 | |||
| 124 | // query whether or not a DB password has been specified as command line |
||
| 125 | // option, if yes override the value from the configuration file |
||
| 126 | if ($password = $input->getOption(InputOptionKeys::DB_PASSWORD)) { |
||
| 127 | $database->setPassword($password); |
||
| 128 | } |
||
| 129 | |||
| 130 | // add the database configuration |
||
| 131 | $instance->addDatabase($database); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | // query whether or not the debug mode has been specified as command line |
||
| 136 | // option, if yes override the value from the configuration file |
||
| 137 | if ($debugMode = $input->getOption(InputOptionKeys::DEBUG_MODE)) { |
||
| 138 | $instance->setDebugMode($instance->mapBoolean($debugMode)); |
||
| 139 | } |
||
| 140 | |||
| 141 | // query whether or not the log level has been specified as command line |
||
| 142 | // option, if yes override the value from the configuration file |
||
| 143 | if ($logLevel = $input->getOption(InputOptionKeys::LOG_LEVEL)) { |
||
| 144 | $instance->setLogLevel($logLevel); |
||
| 145 | } |
||
| 146 | |||
| 147 | // query whether or not a PID filename has been specified as command line |
||
| 148 | // option, if yes override the value from the configuration file |
||
| 149 | if ($pidFilename = $input->getOption(InputOptionKeys::PID_FILENAME)) { |
||
| 150 | $instance->setPidFilename($pidFilename); |
||
| 151 | } |
||
| 152 | |||
| 153 | // extend the plugins with the main configuration instance |
||
| 154 | /** @var \TechDivision\Import\Cli\Configuration\Subject $subject */ |
||
| 155 | foreach ($instance->getPlugins() as $plugin) { |
||
| 156 | // set the configuration instance on the plugin |
||
| 157 | $plugin->setConfiguration($instance); |
||
| 158 | |||
| 159 | // query whether or not the plugin has subjects configured |
||
| 160 | if ($subjects = $plugin->getSubjects()) { |
||
| 161 | // extend the plugin's subjects with the main configuration instance |
||
| 162 | /** @var \TechDivision\Import\Cli\Configuration\Subject $subject */ |
||
| 163 | foreach ($subjects as $subject) { |
||
| 164 | // set the configuration instance on the subject |
||
| 165 | $subject->setConfiguration($instance); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | |||
| 170 | // query whether or not the debug mode is enabled and log level |
||
| 171 | // has NOT been overwritten with a commandline option |
||
| 172 | if ($instance->isDebugMode() && !$input->getOption(InputOptionKeys::LOG_LEVEL)) { |
||
| 173 | // set debug log level, if log level has NOT been overwritten on command line |
||
| 174 | $instance->setLogLevel(LogLevel::DEBUG); |
||
| 175 | } |
||
| 176 | |||
| 177 | // return the initialized configuration instance |
||
| 178 | return $instance; |
||
| 179 | } |
||
| 180 | } |
||
| 181 |