| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 52 | 
| Code Lines | 35 | 
| 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 | ||
| 40 | public function getValidationConstraints() | ||
| 41 |     { | ||
| 42 | return new Assert\Collection([ | ||
| 43 |             'amount' =>  $this->buildElement('float', 1), | ||
| 44 |             'currency' => $this->buildElement('string', 1, ['min' => 3,'max' => 3]), | ||
| 45 |             'settle' => $this->buildElement('bool'), | ||
| 46 |             'order_id' => $this->buildElement('string', 0, ['min' => 2,'max' => 50]), | ||
| 47 |             'description' => $this->buildElement('string', 0, ['max' => 255]), | ||
| 48 |             'country' => $this->buildElement('string', 1, ['min' => 2,'max' => 2]), | ||
| 49 | 'payment_method' => new Assert\Required([ | ||
| 50 | new Assert\Type(['type' => 'string']), | ||
| 51 | new Assert\Choice([ | ||
| 52 | 'choices' => [ | ||
| 53 | self::CARD, | ||
| 54 | self::RECURRING | ||
| 55 | ] | ||
| 56 | ]) | ||
| 57 | ]), | ||
| 58 | 'payment_instrument' => $this->getPaymentInstrumentConstraints( | ||
| 59 | $this->getAttributes()['payment_method'] | ||
| 60 | ), | ||
| 61 | 'threeds2_data' => new Assert\Optional([$this->getThreeDS2DataConstraints()]) | ||
| 62 | ]); | ||
| 63 | } | ||
| 64 | |||
| 65 | private function getPaymentInstrumentConstraints($method) | ||
| 66 |     { | ||
| 67 |         switch ($method) { | ||
| 68 | case self::CARD: | ||
| 69 | return new Assert\Collection([ | ||
| 70 | 'pan' => new Assert\Required([ | ||
| 71 | new Assert\NotBlank(), | ||
| 72 | new Assert\Luhn() | ||
| 73 | ]), | ||
| 74 | 'exp_year' => $this->buildElement( | ||
| 75 | 'integer', 1, | ||
| 76 | ['min' => 4,'max' => 4], | ||
| 77 |                         new Assert\Range(['min' => date('Y')]), | ||
| 78 | ), | ||
|  | |||
| 79 |                     'exp_month' => $this->buildElement('integer', 1), | ||
| 80 |                     'cvc' => $this->buildElement('string', 1, ['min' => 3, 'max' => 4]), | ||
| 81 |                     'holder' => $this->buildElement('string', 1, ['max' => 32]), | ||
| 82 | ]); | ||
| 83 | case self::RECURRING: | ||
| 84 | return new Assert\Collection([ | ||
| 85 |                     'payment_id' => $this->buildElement('string', 1), | ||
| 86 | ]); | ||
| 87 | } | ||
| 88 | |||
| 89 | throw new \InvalidArgumentException( | ||
| 90 | sprintf( | ||
| 91 | 'Payment instrument for payment method "%s" is not expected', | ||
| 92 | $method | ||
| 169 |