| Conditions | 4 |
| Paths | 6 |
| Total Lines | 171 |
| Code Lines | 105 |
| 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 |
||
| 101 | public function execute(InputInterface $input, OutputInterface $output): void |
||
| 102 | { |
||
| 103 | $inputReader = new Helper\InputReader($input, $output, new QuestionHelper()); |
||
| 104 | |||
| 105 | $sources = ['p' => MandateSources::MANDATE_SOURCE_PAPER, 'o' => MandateSources::MANDATE_SOURCE_ONLINE_FORM]; |
||
| 106 | |||
| 107 | $mandateSource = $inputReader->readInput( |
||
| 108 | self::OPTION_SOURCE, |
||
| 109 | Helper\QuestionFactory::createChoiceQuestion( |
||
| 110 | self::OPTION_DESCS[self::OPTION_SOURCE], |
||
| 111 | $sources, |
||
| 112 | MandateSources::MANDATE_SOURCE_ONLINE_FORM |
||
| 113 | ), |
||
| 114 | new Validator\ChoiceValidator($sources) |
||
| 115 | ); |
||
| 116 | |||
| 117 | /** @var \byrokrat\id\IdInterface */ |
||
| 118 | $donorId = null; |
||
| 119 | |||
| 120 | $inputReader->readInput( |
||
| 121 | self::OPTION_ID, |
||
| 122 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_ID]), |
||
| 123 | new Validator\ValidatorCollection( |
||
| 124 | new Validator\IdValidator(), |
||
| 125 | new Validator\CallbackValidator(function (string $value) use (&$donorId) { |
||
| 126 | $donorId = $this->idFactory->createId($value); |
||
| 127 | }) |
||
| 128 | ) |
||
| 129 | ); |
||
| 130 | |||
| 131 | $payerNumber = $inputReader->readInput( |
||
| 132 | self::OPTION_PAYER_NUMBER, |
||
| 133 | Helper\QuestionFactory::createQuestion( |
||
| 134 | self::OPTION_DESCS[self::OPTION_PAYER_NUMBER], |
||
| 135 | $donorId->format('Ssk') |
||
| 136 | ), |
||
| 137 | new Validator\PayerNumberValidator() |
||
| 138 | ); |
||
| 139 | |||
| 140 | /** @var \byrokrat\banking\AccountNumber */ |
||
| 141 | $account = null; |
||
| 142 | |||
| 143 | $inputReader->readInput( |
||
| 144 | self::OPTION_ACCOUNT, |
||
| 145 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_ACCOUNT])->setAutocompleterValues( |
||
| 146 | ["3300,{$donorId->format('Ssk')}"] |
||
| 147 | ), |
||
| 148 | new Validator\ValidatorCollection( |
||
| 149 | new Validator\AccountValidator(), |
||
| 150 | new Validator\CallbackValidator(function (string $value) use (&$account) { |
||
| 151 | $account = $this->accountFactory->createAccount($value); |
||
| 152 | }) |
||
| 153 | ) |
||
| 154 | ); |
||
| 155 | |||
| 156 | $donationAmount = $this->moneyParser->parse( |
||
| 157 | $inputReader->readInput( |
||
| 158 | self::OPTION_AMOUNT, |
||
| 159 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_AMOUNT]), |
||
| 160 | new Validator\ValidatorCollection( |
||
| 161 | new Validator\NotEmptyValidator(), |
||
| 162 | new Validator\NumericValidator() |
||
| 163 | ) |
||
| 164 | ), |
||
| 165 | new Currency('SEK') |
||
| 166 | ); |
||
| 167 | |||
| 168 | $name = $inputReader->readInput( |
||
| 169 | self::OPTION_NAME, |
||
| 170 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_NAME]), |
||
| 171 | new Validator\ValidatorCollection( |
||
| 172 | new Validator\StringValidator(), |
||
| 173 | new Validator\NotEmptyValidator() |
||
| 174 | ) |
||
| 175 | ); |
||
| 176 | |||
| 177 | $postalAddress = new PostalAddress( |
||
| 178 | $inputReader->readInput( |
||
| 179 | self::OPTION_ADDRESS1, |
||
| 180 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_ADDRESS1], ''), |
||
| 181 | new Validator\StringValidator() |
||
| 182 | ), |
||
| 183 | $inputReader->readInput( |
||
| 184 | self::OPTION_ADDRESS2, |
||
| 185 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_ADDRESS2], ''), |
||
| 186 | new Validator\StringValidator() |
||
| 187 | ), |
||
| 188 | $inputReader->readInput( |
||
| 189 | self::OPTION_ADDRESS3, |
||
| 190 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_ADDRESS3], ''), |
||
| 191 | new Validator\StringValidator() |
||
| 192 | ), |
||
| 193 | $inputReader->readInput( |
||
| 194 | self::OPTION_POSTAL_CODE, |
||
| 195 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_POSTAL_CODE], ''), |
||
| 196 | new Validator\PostalCodeValidator() |
||
| 197 | ), |
||
| 198 | $inputReader->readInput( |
||
| 199 | self::OPTION_POSTAL_CITY, |
||
| 200 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_POSTAL_CITY], ''), |
||
| 201 | new Validator\StringValidator() |
||
| 202 | ) |
||
| 203 | ); |
||
| 204 | |||
| 205 | $email = $inputReader->readInput( |
||
| 206 | self::OPTION_EMAIL, |
||
| 207 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_EMAIL], ''), |
||
| 208 | new Validator\EmailValidator() |
||
| 209 | ); |
||
| 210 | |||
| 211 | $phone = $inputReader->readInput( |
||
| 212 | self::OPTION_PHONE, |
||
| 213 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_PHONE], ''), |
||
| 214 | new Validator\PhoneValidator() |
||
| 215 | ); |
||
| 216 | |||
| 217 | $comment = $inputReader->readInput( |
||
| 218 | self::OPTION_COMMENT, |
||
| 219 | Helper\QuestionFactory::createQuestion(self::OPTION_DESCS[self::OPTION_COMMENT], ''), |
||
| 220 | new Validator\StringValidator() |
||
| 221 | ); |
||
| 222 | |||
| 223 | $attributes = []; |
||
| 224 | |||
| 225 | /** @var array<string> */ |
||
| 226 | $attrKeys = $input->getOption(self::OPTION_ATTR_KEY); |
||
| 227 | |||
| 228 | /** @var array<string> */ |
||
| 229 | $attrValues = $input->getOption(self::OPTION_ATTR_VALUE); |
||
| 230 | |||
| 231 | for ($count = 0;; $count++) { |
||
| 232 | $attrKey = $inputReader->readInput( |
||
| 233 | '', |
||
| 234 | Helper\QuestionFactory::createQuestion('Add an attribute (empty to skip)', $attrKeys[$count] ?? ''), |
||
| 235 | new Validator\StringValidator() |
||
| 236 | ); |
||
| 237 | |||
| 238 | if (!$attrKey) { |
||
| 239 | break; |
||
| 240 | } |
||
| 241 | |||
| 242 | $attributes[$attrKey] = $inputReader->readInput( |
||
| 243 | '', |
||
| 244 | Helper\QuestionFactory::createQuestion('Value', $attrValues[$count] ?? ''), |
||
| 245 | new Validator\StringValidator() |
||
| 246 | ); |
||
| 247 | } |
||
| 248 | |||
| 249 | $this->commandBus->handle( |
||
| 250 | new AddDonor(new NewDonor($mandateSource, $payerNumber, $account, $donorId, $donationAmount)) |
||
| 251 | ); |
||
| 252 | |||
| 253 | $donor = $this->donorRepository->requireByPayerNumber($payerNumber); |
||
| 254 | |||
| 255 | $this->commandBus->handle(new UpdateState($donor, NewMandate::getStateId(), 'Mandate added manually')); |
||
| 256 | |||
| 257 | $this->commandBus->handle(new UpdateName($donor, $name)); |
||
| 258 | |||
| 259 | $this->commandBus->handle(new UpdatePostalAddress($donor, $postalAddress)); |
||
| 260 | |||
| 261 | $this->commandBus->handle(new UpdateEmail($donor, $email)); |
||
| 262 | |||
| 263 | $this->commandBus->handle(new UpdatePhone($donor, $phone)); |
||
| 264 | |||
| 265 | $this->commandBus->handle(new UpdateComment($donor, $comment)); |
||
| 266 | |||
| 267 | foreach ($attributes as $attrKey => $attrValue) { |
||
| 268 | $this->commandBus->handle(new UpdateAttribute($donor, $attrKey, $attrValue)); |
||
| 269 | } |
||
| 270 | |||
| 271 | $this->evaluateDryRun($input); |
||
| 272 | } |
||
| 274 |