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