Test Failed
Push — develop ( 7cb291...9cc0c5 )
by Reüel
03:00
created

src/DirectLink/Client.php (4 issues)

1
<?php
2
3
namespace Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink;
4
5
use Pronamic\WordPress\Pay\Core\Util;
6
use Pronamic\WordPress\Pay\Core\XML\Security;
7
use Pronamic\WordPress\Pay\Gateways\Ingenico\DirectLink;
8
use Pronamic\WordPress\Pay\Gateways\Ingenico\Error;
9
use Pronamic\WordPress\Pay\Gateways\Ingenico\XML\OrderResponseParser;
10
use WP_Error;
0 ignored issues
show
The type WP_Error was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
/**
13
 * Title: Ingenico DirectLink client
14
 * Description:
15
 * Copyright: 2005-2019 Pronamic
16
 * Company: Pronamic
17
 *
18
 * @author  Remco Tolsma
19
 * @version 2.0.0
20
 * @since   1.0.0
21
 */
22
class Client {
23
	/**
24
	 * Error.
25
	 *
26
	 * @var WP_Error
27
	 */
28
	private $error;
29
30
	/**
31
	 * API URL.
32
	 *
33
	 * @var string
34
	 */
35
	public $api_url;
36
37
	/**
38
	 * PSP ID.
39
	 *
40
	 * @var string
41
	 */
42
	public $psp_id;
43
44
	/**
45
	 * SHA IN.
46
	 *
47
	 * @var string
48
	 */
49
	public $sha_in;
50
51
	/**
52
	 * User ID.
53
	 *
54
	 * @var string
55
	 */
56
	public $user_id;
57
58
	/**
59
	 * Password.
60
	 *
61
	 * @var string
62
	 */
63
	public $password;
64
65
	/**
66
	 * Constructs and initializes an Ogone DirectLink client
67
	 */
68
	public function __construct() {
69
		$this->api_url = DirectLink::API_PRODUCTION_URL;
70
	}
71
72
	/**
73
	 * Get error
74
	 *
75
	 * @return WP_Error
76
	 */
77
	public function get_error() {
78
		return $this->error;
79
	}
80
81
	/**
82
	 * Order direct
83
	 *
84
	 * @param array $data Data.
85
	 *
86
	 * @return bool|OrderResponse
87
	 */
88
	public function order_direct( array $data = array() ) {
89
		$order_response = false;
90
91
		$result = Util::remote_get_body(
92
			$this->api_url,
93
			200,
94
			array(
95
				'method'    => 'POST',
96
				'sslverify' => false,
97
				'body'      => $data,
98
			)
99
		);
100
101
		if ( is_wp_error( $result ) ) {
0 ignored issues
show
The function is_wp_error was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
		if ( /** @scrutinizer ignore-call */ is_wp_error( $result ) ) {
Loading history...
102
			$this->error = $result;
103
		} else {
104
			$xml = Util::simplexml_load_string( $result );
0 ignored issues
show
It seems like $result can also be of type array; however, parameter $string of Pronamic\WordPress\Pay\C...simplexml_load_string() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
			$xml = Util::simplexml_load_string( /** @scrutinizer ignore-type */ $result );
Loading history...
105
106
			if ( is_wp_error( $xml ) ) {
107
				$this->error = $xml;
0 ignored issues
show
Documentation Bug introduced by
It seems like $xml of type SimpleXMLElement is incompatible with the declared type WP_Error of property $error.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
108
			} else {
109
				$order_response = OrderResponseParser::parse( $xml );
110
111
				if ( ! empty( $order_response->nc_error ) ) {
112
					$ogone_error = new Error(
113
						Security::filter( $order_response->nc_error ),
114
						Security::filter( $order_response->nc_error_plus )
115
					);
116
117
					$this->error = new WP_Error( 'ogone_error', (string) $ogone_error, $ogone_error );
118
				}
119
			}
120
		}
121
122
		return $order_response;
123
	}
124
}
125