| Conditions | 1 |
| Paths | 1 |
| Total Lines | 55 |
| Code Lines | 48 |
| 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 |
||
| 19 | public function testGet(): void { |
||
| 20 | $client = new Client( '47:11:00' ); |
||
| 21 | |||
| 22 | $amount = Euro::newFromCents( 500 ); |
||
| 23 | $amountConvertedToFloat = $amount->getEuroFloat(); |
||
| 24 | |||
| 25 | $api = $this->createMock( Sofortueberweisung::class ); |
||
| 26 | |||
| 27 | $api |
||
| 28 | ->method( 'setAmount' ) |
||
| 29 | ->with( $amountConvertedToFloat ); |
||
| 30 | $api |
||
| 31 | ->method( 'setCurrencyCode' ) |
||
| 32 | ->with( 'EUR' ); |
||
| 33 | $api |
||
| 34 | ->method( 'setReason' ) |
||
| 35 | ->with( 'Donation', '529836' ); |
||
| 36 | $api |
||
| 37 | ->method( 'setSuccessUrl' ) |
||
| 38 | ->with( 'https://us.org/yes?id=529836&accessToken=letmein', true ); |
||
| 39 | $api |
||
| 40 | ->method( 'setAbortUrl' ) |
||
| 41 | ->with( 'https://us.org/no' ); |
||
| 42 | $api |
||
| 43 | ->method( 'setNotificationUrl' ) |
||
| 44 | ->with( 'https://us.org/callback' ); |
||
| 45 | $api |
||
| 46 | ->method( 'sendRequest' ); |
||
| 47 | $api |
||
| 48 | ->method( 'isError' ) |
||
| 49 | ->willReturn( false ); |
||
| 50 | $api |
||
| 51 | ->expects( $this->never() ) |
||
| 52 | ->method( 'getError' ); |
||
| 53 | $api |
||
| 54 | ->method( 'getTransactionId' ) |
||
| 55 | ->willReturn( 'tr4ns4ct10n' ); |
||
| 56 | $api |
||
| 57 | ->method( 'getPaymentUrl' ) |
||
| 58 | ->willReturn( 'https://awsomepaymentprovider.tld/784trhhrf4' ); |
||
| 59 | |||
| 60 | $client->setApi( $api ); |
||
| 61 | |||
| 62 | $request = new Request(); |
||
| 63 | $request->setAmount( $amount ); |
||
| 64 | $request->setCurrencyCode( 'EUR' ); |
||
| 65 | $request->setReasons( [ 'Donation', '529836' ] ); |
||
| 66 | $request->setSuccessUrl( 'https://us.org/yes?id=529836&accessToken=letmein' ); |
||
| 67 | $request->setAbortUrl( 'https://us.org/no' ); |
||
| 68 | $request->setNotificationUrl( 'https://us.org/callback' ); |
||
| 69 | $response = $client->get( $request ); |
||
| 70 | |||
| 71 | $this->assertSame( 'https://awsomepaymentprovider.tld/784trhhrf4', $response->getPaymentUrl() ); |
||
| 72 | $this->assertSame( 'tr4ns4ct10n', $response->getTransactionId() ); |
||
| 73 | } |
||
| 74 | |||
| 103 |