| Conditions | 5 |
| Paths | 4 |
| Total Lines | 121 |
| Code Lines | 76 |
| 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 |
||
| 108 | public function processMandate(Xml\XmlMandate $xmlMandate): Xml\XmlMandate |
||
| 109 | { |
||
| 110 | if (is_null($this->input) || is_null($this->output)) { |
||
| 111 | throw new \LogicException("Input or output not set, did you call execute() prior to processMandate()?"); |
||
| 112 | } |
||
| 113 | |||
| 114 | $this->output->writeln('<info>New mandate</info>'); |
||
| 115 | |||
| 116 | $this->output->writeln( |
||
| 117 | (new Xml\HumanDumper($this->moneyFormatter))->dump($xmlMandate) |
||
| 118 | ); |
||
| 119 | |||
| 120 | $inputReader = new Helper\InputReader($this->input, $this->output, new QuestionHelper()); |
||
| 121 | |||
| 122 | if (!$inputReader->confirm("Edit [<info>y/N</info>]? ", false)) { |
||
| 123 | return $xmlMandate; |
||
| 124 | } |
||
| 125 | |||
| 126 | $inputReader->readOptionalInput( |
||
| 127 | self::OPTION_ID, |
||
| 128 | $xmlMandate->donorId->format('CS-sk'), |
||
| 129 | new Validator\ValidatorCollection( |
||
| 130 | new Validator\IdValidator(), |
||
| 131 | new Validator\CallbackValidator(function (string $value) use (&$xmlMandate) { |
||
| 132 | $xmlMandate->donorId = $this->idFactory->createId($value); |
||
| 133 | }) |
||
| 134 | ) |
||
| 135 | ); |
||
| 136 | |||
| 137 | $xmlMandate->payerNumber = $inputReader->readOptionalInput( |
||
| 138 | self::OPTION_PAYER_NUMBER, |
||
| 139 | $xmlMandate->payerNumber, |
||
| 140 | new Validator\PayerNumberValidator() |
||
| 141 | ); |
||
| 142 | |||
| 143 | $inputReader->readOptionalInput( |
||
| 144 | self::OPTION_ACCOUNT, |
||
| 145 | $xmlMandate->account->prettyprint(), |
||
| 146 | new Validator\ValidatorCollection( |
||
| 147 | new Validator\AccountValidator(), |
||
| 148 | new Validator\CallbackValidator(function (string $value) use (&$xmlMandate) { |
||
| 149 | $xmlMandate->account = $this->accountFactory->createAccount($value); |
||
| 150 | }) |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | |||
| 154 | $xmlMandate->donationAmount = $this->moneyParser->parse( |
||
| 155 | $inputReader->readOptionalInput( |
||
| 156 | self::OPTION_AMOUNT, |
||
| 157 | $this->moneyFormatter->format($xmlMandate->donationAmount), |
||
| 158 | new Validator\ValidatorCollection( |
||
| 159 | new Validator\NotEmptyValidator(), |
||
| 160 | new Validator\NumericValidator() |
||
| 161 | ) |
||
| 162 | ), |
||
| 163 | new Currency('SEK') |
||
| 164 | ); |
||
| 165 | |||
| 166 | $xmlMandate->name = $inputReader->readOptionalInput( |
||
| 167 | self::OPTION_NAME, |
||
| 168 | $xmlMandate->name, |
||
| 169 | new Validator\ValidatorCollection( |
||
| 170 | new Validator\StringValidator(), |
||
| 171 | new Validator\NotEmptyValidator() |
||
| 172 | ) |
||
| 173 | ); |
||
| 174 | |||
| 175 | $xmlMandate->address['line1'] = $inputReader->readOptionalInput( |
||
| 176 | self::OPTION_ADDRESS1, |
||
| 177 | $xmlMandate->address['line1'], |
||
| 178 | new Validator\StringValidator() |
||
| 179 | ); |
||
| 180 | |||
| 181 | $xmlMandate->address['line2'] = $inputReader->readOptionalInput( |
||
| 182 | self::OPTION_ADDRESS2, |
||
| 183 | $xmlMandate->address['line2'], |
||
| 184 | new Validator\StringValidator() |
||
| 185 | ); |
||
| 186 | |||
| 187 | $xmlMandate->address['line3'] = $inputReader->readOptionalInput( |
||
| 188 | self::OPTION_ADDRESS3, |
||
| 189 | $xmlMandate->address['line3'], |
||
| 190 | new Validator\StringValidator() |
||
| 191 | ); |
||
| 192 | |||
| 193 | $xmlMandate->address['postalCode'] = $inputReader->readOptionalInput( |
||
| 194 | self::OPTION_POSTAL_CODE, |
||
| 195 | $xmlMandate->address['postalCode'], |
||
| 196 | new Validator\PostalCodeValidator() |
||
| 197 | ); |
||
| 198 | |||
| 199 | $xmlMandate->address['postalCity'] = $inputReader->readOptionalInput( |
||
| 200 | self::OPTION_POSTAL_CITY, |
||
| 201 | $xmlMandate->address['postalCity'], |
||
| 202 | new Validator\StringValidator() |
||
| 203 | ); |
||
| 204 | |||
| 205 | $xmlMandate->email = $inputReader->readOptionalInput( |
||
| 206 | self::OPTION_EMAIL, |
||
| 207 | $xmlMandate->email, |
||
| 208 | new Validator\EmailValidator() |
||
| 209 | ); |
||
| 210 | |||
| 211 | $xmlMandate->phone = $inputReader->readOptionalInput( |
||
| 212 | self::OPTION_PHONE, |
||
| 213 | $xmlMandate->phone, |
||
| 214 | new Validator\PhoneValidator() |
||
| 215 | ); |
||
| 216 | |||
| 217 | $xmlMandate->comment = $inputReader->readOptionalInput( |
||
| 218 | self::OPTION_COMMENT, |
||
| 219 | $xmlMandate->comment, |
||
| 220 | new Validator\StringValidator() |
||
| 221 | ); |
||
| 222 | |||
| 223 | foreach ($xmlMandate->attributes as $attrKey => $attrValue) { |
||
| 224 | $xmlMandate->attributes[$attrKey] = |
||
| 225 | $inputReader->readOptionalInput("attribute.$attrKey", $attrValue, new Validator\StringValidator()); |
||
| 226 | } |
||
| 227 | |||
| 228 | return $xmlMandate; |
||
| 229 | } |
||
| 231 |