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