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