| Conditions | 5 |
| Paths | 2 |
| Total Lines | 59 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | 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 |
||
| 113 | protected function checkMagentoConnectCredentials(OutputInterface $output) |
||
| 114 | { |
||
| 115 | $configKey = 'http-basic.repo.magento.com'; |
||
| 116 | |||
| 117 | $composerHelper = $this->getCommand()->getHelper('composer'); |
||
| 118 | /** @var $composerHelper ComposerHelper */ |
||
| 119 | $authConfig = $composerHelper->getConfigValue($configKey); |
||
| 120 | |||
| 121 | if (!isset($authConfig->username) |
||
| 122 | || !isset($authConfig->password) |
||
| 123 | ) { |
||
| 124 | $this->output->writeln(array( |
||
| 125 | '', |
||
| 126 | $this->getCommand() |
||
| 127 | ->getHelperSet() |
||
| 128 | ->get('formatter') |
||
| 129 | ->formatBlock('Authentication', 'bg=blue;fg=white', true), |
||
| 130 | '', |
||
| 131 | )); |
||
| 132 | |||
| 133 | $this->output->writeln(array( |
||
| 134 | 'You need to create a secury key. Login at magentocommerce.com.', |
||
| 135 | 'Developers -> Secure Keys. <info>Use public key as username and private key as password</info>', |
||
| 136 | '' |
||
| 137 | )); |
||
| 138 | $dialog = $this->getCommand()->getHelper('dialog'); |
||
| 139 | |||
| 140 | $username = $dialog->askAndValidate( |
||
| 141 | $output, |
||
| 142 | '<comment>Please enter your public key: </comment>', |
||
| 143 | function ($value) { |
||
| 144 | if ('' === trim($value)) { |
||
| 145 | throw new Exception('The private key (auth token) can not be empty'); |
||
| 146 | } |
||
| 147 | |||
| 148 | return $value; |
||
| 149 | }, |
||
| 150 | 20, |
||
| 151 | false |
||
| 152 | ); |
||
| 153 | |||
| 154 | |||
| 155 | $password = $dialog->askHiddenResponseAndValidate( |
||
| 156 | $output, |
||
| 157 | '<comment>Please enter your private key: </comment>', |
||
| 158 | function ($value) { |
||
| 159 | if ('' === trim($value)) { |
||
| 160 | throw new Exception('The private key (auth token) can not be empty'); |
||
| 161 | } |
||
| 162 | |||
| 163 | return $value; |
||
| 164 | }, |
||
| 165 | 20, |
||
| 166 | false |
||
| 167 | ); |
||
| 168 | |||
| 169 | $composerHelper->setConfigValue($configKey, [$username, $password]); |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 |