| Conditions | 4 |
| Paths | 4 |
| Total Lines | 102 |
| Code Lines | 66 |
| 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 |
||
| 119 | private function processMandate(XmlMandate $xmlMandate, Helper\InputReader $inputReader): void |
||
| 120 | { |
||
| 121 | $inputReader->readOptionalInput( |
||
| 122 | 'donorId', |
||
| 123 | $xmlMandate->donorId->format('CS-sk'), |
||
| 124 | new Validator\ValidatorCollection( |
||
| 125 | new Validator\IdValidator, |
||
| 126 | new Validator\CallbackValidator(function (string $value) use (&$xmlMandate) { |
||
| 127 | $xmlMandate->donorId = $this->idFactory->createId($value); |
||
| 128 | }) |
||
| 129 | ) |
||
| 130 | ); |
||
| 131 | |||
| 132 | $xmlMandate->payerNumber = $inputReader->readOptionalInput( |
||
| 133 | 'payer-number', |
||
| 134 | $xmlMandate->payerNumber ?: $xmlMandate->donorId->format('Ssk'), |
||
| 135 | new Validator\PayerNumberValidator |
||
| 136 | ); |
||
| 137 | |||
| 138 | $inputReader->readOptionalInput( |
||
| 139 | 'account', |
||
| 140 | $xmlMandate->account->prettyprint(), |
||
| 141 | new Validator\ValidatorCollection( |
||
| 142 | new Validator\AccountValidator, |
||
| 143 | new Validator\CallbackValidator(function (string $value) use (&$xmlMandate) { |
||
| 144 | $xmlMandate->account = $this->accountFactory->createAccount($value); |
||
| 145 | }) |
||
| 146 | ) |
||
| 147 | ); |
||
| 148 | |||
| 149 | $xmlMandate->name = $inputReader->readOptionalInput( |
||
| 150 | 'name', |
||
| 151 | $xmlMandate->name, |
||
| 152 | new Validator\ValidatorCollection( |
||
| 153 | new Validator\StringValidator, |
||
| 154 | new Validator\NotEmptyValidator |
||
| 155 | ) |
||
| 156 | ); |
||
| 157 | |||
| 158 | $xmlMandate->address['line1'] = $inputReader->readOptionalInput( |
||
| 159 | 'address1', |
||
| 160 | $xmlMandate->address['line1'], |
||
| 161 | new Validator\StringValidator |
||
| 162 | ); |
||
| 163 | |||
| 164 | $xmlMandate->address['line2'] = $inputReader->readOptionalInput( |
||
| 165 | 'address2', |
||
| 166 | $xmlMandate->address['line2'], |
||
| 167 | new Validator\StringValidator |
||
| 168 | ); |
||
| 169 | |||
| 170 | $xmlMandate->address['line3'] = $inputReader->readOptionalInput( |
||
| 171 | 'address3', |
||
| 172 | $xmlMandate->address['line3'], |
||
| 173 | new Validator\StringValidator |
||
| 174 | ); |
||
| 175 | |||
| 176 | $xmlMandate->address['postalCode'] = $inputReader->readOptionalInput( |
||
| 177 | 'postal-code', |
||
| 178 | $xmlMandate->address['postalCode'], |
||
| 179 | new Validator\PostalCodeValidator |
||
| 180 | ); |
||
| 181 | |||
| 182 | $xmlMandate->address['postalCity'] = $inputReader->readOptionalInput( |
||
| 183 | 'postal-city', |
||
| 184 | $xmlMandate->address['postalCity'], |
||
| 185 | new Validator\StringValidator |
||
| 186 | ); |
||
| 187 | |||
| 188 | foreach ($xmlMandate->attributes as $attrKey => $attrValue) { |
||
| 189 | $xmlMandate->attributes[$attrKey] = |
||
| 190 | $inputReader->readOptionalInput("attribute.$attrKey", $attrValue, new Validator\StringValidator); |
||
| 191 | } |
||
| 192 | |||
| 193 | $this->commandBus->handle( |
||
| 194 | new AddDonor( |
||
| 195 | new NewDonor( |
||
| 196 | MandateSources::MANDATE_SOURCE_ONLINE_FORM, |
||
| 197 | $xmlMandate->payerNumber, |
||
| 198 | $xmlMandate->account, |
||
| 199 | $xmlMandate->donorId, |
||
| 200 | Money::SEK('0') |
||
| 201 | ) |
||
| 202 | ) |
||
| 203 | ); |
||
| 204 | |||
| 205 | $donor = $this->donorRepository->requireByPayerNumber($xmlMandate->payerNumber); |
||
| 206 | |||
| 207 | $this->commandBus->handle(new UpdateState($donor, NewMandate::getStateId(), 'Mandate added from xml')); |
||
| 208 | |||
| 209 | $this->commandBus->handle(new UpdateName($donor, $xmlMandate->name)); |
||
| 210 | |||
| 211 | $this->commandBus->handle(new UpdatePostalAddress($donor, new PostalAddress( |
||
| 212 | $xmlMandate->address['line1'], |
||
| 213 | $xmlMandate->address['line2'], |
||
| 214 | $xmlMandate->address['line3'], |
||
| 215 | $xmlMandate->address['postalCode'], |
||
| 216 | $xmlMandate->address['postalCity'], |
||
| 217 | ))); |
||
| 218 | |||
| 219 | foreach ($xmlMandate->attributes as $attrKey => $attrValue) { |
||
| 220 | $this->commandBus->handle(new UpdateAttribute($donor, $attrKey, $attrValue)); |
||
| 221 | } |
||
| 224 |