| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 17 | public function testSend() |
||
| 18 | { |
||
| 19 | $apiClient = $this->getMockBuilder(ApiClient::class) |
||
| 20 | ->disableOriginalConstructor() |
||
| 21 | ->getMock(); |
||
| 22 | |||
| 23 | $apiClient->expects(self::once())->method('post') |
||
| 24 | ->with('payment/init', [ |
||
| 25 | 'merchantId' => '012345', |
||
| 26 | 'orderNo' => '5547', |
||
| 27 | 'payOperation' => 'payment', |
||
| 28 | 'payMethod' => 'card', |
||
| 29 | 'totalAmount' => 1789600.0, |
||
| 30 | 'currency' => 'CZK', |
||
| 31 | 'closePayment' => true, |
||
| 32 | 'returnUrl' => 'https://vasobchod.cz/gateway-return', |
||
| 33 | 'returnMethod' => 'POST', |
||
| 34 | 'cart' => [ |
||
| 35 | [ |
||
| 36 | 'name' => 'Nákup na vasobchodcz', |
||
| 37 | 'quantity' => 1, |
||
| 38 | 'amount' => 1789600, |
||
| 39 | 'description' => 'Lenovo ThinkPad Edge E540', |
||
| 40 | ], |
||
| 41 | [ |
||
| 42 | 'name' => 'Poštovné', |
||
| 43 | 'quantity' => 1, |
||
| 44 | 'amount' => 0, |
||
| 45 | 'description' => 'Doprava PPL', |
||
| 46 | ], |
||
| 47 | ], |
||
| 48 | 'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', |
||
| 49 | 'merchantData' => base64_encode('some-base64-encoded-merchant-data'), |
||
| 50 | 'customerId' => '123', |
||
| 51 | 'language' => 'CZ', |
||
| 52 | ]) |
||
| 53 | ->willReturn( |
||
| 54 | new Response(new ResponseCode(ResponseCode::S200_OK), [ |
||
| 55 | 'payId' => '123456789', |
||
| 56 | 'dttm' => '20140425131559', |
||
| 57 | 'resultCode' => 0, |
||
| 58 | 'resultMessage' => 'OK', |
||
| 59 | 'paymentStatus' => 1, |
||
| 60 | ]) |
||
| 61 | ); |
||
| 62 | |||
| 63 | /** @var ApiClient $apiClient */ |
||
| 64 | $cart = new Cart( |
||
| 65 | new Currency(Currency::CZK) |
||
| 66 | ); |
||
| 67 | $cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540'); |
||
| 68 | $cart->addItem('Poštovné', 1, 0, 'Doprava PPL'); |
||
| 69 | |||
| 70 | $initPaymentRequest = new InitPaymentRequest( |
||
| 71 | '012345', |
||
| 72 | '5547', |
||
| 73 | new PayOperation(PayOperation::PAYMENT), |
||
| 74 | new PayMethod(PayMethod::CARD), |
||
| 75 | true, |
||
| 76 | 'https://vasobchod.cz/gateway-return', |
||
| 77 | new HttpMethod(HttpMethod::POST), |
||
| 78 | $cart, |
||
| 79 | 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', |
||
| 80 | 'some-base64-encoded-merchant-data', |
||
| 81 | '123', |
||
| 82 | new Language(Language::CZ) |
||
| 83 | ); |
||
| 84 | |||
| 85 | $paymentResponse = $initPaymentRequest->send($apiClient); |
||
| 86 | |||
| 87 | $this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
||
| 88 | $this->assertSame('123456789', $paymentResponse->getPayId()); |
||
| 89 | $this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
||
| 90 | $this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
||
| 91 | $this->assertSame('OK', $paymentResponse->getResultMessage()); |
||
| 92 | $this->assertEquals(new PaymentStatus(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus()); |
||
| 93 | $this->assertNull($paymentResponse->getAuthCode()); |
||
| 94 | } |
||
| 95 | |||
| 97 |