Failed Conditions
Push — main ( e106fe...b61967 )
by Remco
09:42 queued 16s
created

PaymentRequestTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A test() 0 21 1
1
<?php
2
/**
3
 * Payment Request Test
4
 *
5
 * @author    Pronamic <[email protected]>
6
 * @copyright 2005-2021 Pronamic
7
 * @license   GPL-3.0-or-later
8
 * @package   Pronamic\WordPress\Pay\Gateways\Payvision
9
 */
10
11
namespace Pronamic\WordPress\Pay\Gateways\Payvision;
12
13
/**
14
 * Payment Request Test
15
 *
16
 * @author  Remco Tolsma
17
 * @version 1.1.0
18
 * @since   1.0.0
19
 */
20
class PaymentRequestTest extends \WP_UnitTestCase {
21
	/**
22
	 * Test.
23
	 */
24
	public function test() {
25
		$header = new RequestHeader( '123456' );
26
27
		$transaction = new Transaction( '1', 50, 'EUR', '12345678' );
0 ignored issues
show
Documentation introduced by
'12345678' is of type string, but the function expects a object<Pronamic\WordPres...Payvision\TrackingCode>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
29
		$payment_request = new PaymentRequest( $header, $transaction );
30
31
		$bank = new BankDetails();
32
		$bank->set_issuer_id( IssuerIdIDeal::ABN_AMRO );
33
34
		$payment_request->set_bank( $bank );
35
36
		$this->assertInstanceOf( PaymentRequest::class, $payment_request );
37
38
		// JSON.
39
		$json_file = __DIR__ . '/../json/payment-request.json';
40
41
		$json_string = \wp_json_encode( $payment_request, \JSON_PRETTY_PRINT );
42
43
		$this->assertJsonStringEqualsJsonFile( $json_file, $json_string );
0 ignored issues
show
Security Bug introduced by
It seems like $json_string defined by \wp_json_encode($payment...st, \JSON_PRETTY_PRINT) on line 41 can also be of type false; however, PHPUnit\Framework\Assert...nStringEqualsJsonFile() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
44
	}
45
}
46