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