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; |
||||
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 ) ) { |
||||
102 | $this->error = $result; |
||||
0 ignored issues
–
show
|
|||||
103 | } else { |
||||
104 | $xml = Util::simplexml_load_string( $result ); |
||||
0 ignored issues
–
show
It seems like
$result can also be of type WP_Error ; 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
![]() |
|||||
105 | |||||
106 | if ( is_wp_error( $xml ) ) { |
||||
107 | $this->error = $xml; |
||||
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 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.