Passed
Push — master ( 8b5318...99a753 )
by Remco
09:00
created
src/Error.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	 * @param string $code    Code.
46 46
 	 * @param string $message Message.
47 47
 	 */
48
-	public function __construct( $code, $message ) {
48
+	public function __construct($code, $message) {
49 49
 		$this->code    = $code;
50 50
 		$this->message = $message;
51 51
 	}
@@ -75,18 +75,18 @@  discard block
 block discarded – undo
75 75
 	 * @return Error
76 76
 	 * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties.
77 77
 	 */
78
-	public static function from_object( stdClass $object ) {
79
-		if ( ! isset( $object->errorCode ) ) {
80
-			throw new InvalidArgumentException( 'Object must contain `errorCode` property.' );
78
+	public static function from_object(stdClass $object) {
79
+		if ( ! isset($object->errorCode)) {
80
+			throw new InvalidArgumentException('Object must contain `errorCode` property.');
81 81
 		}
82 82
 
83 83
 		$message = null;
84 84
 
85
-		if ( isset( $object->errorMessage ) ) {
85
+		if (isset($object->errorMessage)) {
86 86
 			$message = $object->errorMessage;
87 87
 		}
88 88
 
89
-		if ( isset( $object->consumerMessage ) ) {
89
+		if (isset($object->consumerMessage)) {
90 90
 			$message = $object->consumerMessage;
91 91
 		}
92 92
 
@@ -103,19 +103,19 @@  discard block
 block discarded – undo
103 103
 	 * @return Error
104 104
 	 * @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
105 105
 	 */
106
-	public static function from_json( $json ) {
107
-		$data = json_decode( $json );
106
+	public static function from_json($json) {
107
+		$data = json_decode($json);
108 108
 
109 109
 		$validator = new Validator();
110 110
 
111 111
 		$validator->validate(
112 112
 			$data,
113 113
 			(object) array(
114
-				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/json-schema-error.json' ),
114
+				'$ref' => 'file://' . realpath(__DIR__ . '/../json-schemas/json-schema-error.json'),
115 115
 			),
116 116
 			Constraint::CHECK_MODE_EXCEPTIONS
117 117
 		);
118 118
 
119
-		return self::from_object( $data );
119
+		return self::from_object($data);
120 120
 	}
121 121
 }
Please login to merge, or discard this patch.
src/Money.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @param string $currency Authentication.
45 45
 	 * @param int    $amount   Amount.
46 46
 	 */
47
-	public function __construct( $currency, $amount ) {
47
+	public function __construct($currency, $amount) {
48 48
 		$this->currency = $currency;
49 49
 		$this->amount   = $amount;
50 50
 	}
@@ -86,13 +86,13 @@  discard block
 block discarded – undo
86 86
 	 * @return Money
87 87
 	 * @throws InvalidArgumentException Throws invalid argument exception when object does not contains the required properties.
88 88
 	 */
89
-	public static function from_object( stdClass $object ) {
90
-		if ( ! isset( $object->currency ) ) {
91
-			throw new InvalidArgumentException( 'Object must contain `currency` property.' );
89
+	public static function from_object(stdClass $object) {
90
+		if ( ! isset($object->currency)) {
91
+			throw new InvalidArgumentException('Object must contain `currency` property.');
92 92
 		}
93 93
 
94
-		if ( ! isset( $object->amount ) ) {
95
-			throw new InvalidArgumentException( 'Object must contain `amount` property.' );
94
+		if ( ! isset($object->amount)) {
95
+			throw new InvalidArgumentException('Object must contain `amount` property.');
96 96
 		}
97 97
 
98 98
 		return new self(
@@ -108,19 +108,19 @@  discard block
 block discarded – undo
108 108
 	 * @return Money
109 109
 	 * @throws \JsonSchema\Exception\ValidationException Throws JSON schema validation exception when JSON is invalid.
110 110
 	 */
111
-	public static function from_json( $json ) {
112
-		$data = json_decode( $json );
111
+	public static function from_json($json) {
112
+		$data = json_decode($json);
113 113
 
114 114
 		$validator = new Validator();
115 115
 
116 116
 		$validator->validate(
117 117
 			$data,
118 118
 			(object) array(
119
-				'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/json-schema-money.json' ),
119
+				'$ref' => 'file://' . realpath(__DIR__ . '/../json-schemas/json-schema-money.json'),
120 120
 			),
121 121
 			Constraint::CHECK_MODE_EXCEPTIONS
122 122
 		);
123 123
 
124
-		return self::from_object( $data );
124
+		return self::from_object($data);
125 125
 	}
126 126
 }
Please login to merge, or discard this patch.
src/ConfigFactory.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -26,16 +26,16 @@
 block discarded – undo
26 26
 	 * @param string $post_id Post ID.
27 27
 	 * @return Config
28 28
 	 */
29
-	public function get_config( $post_id ) {
29
+	public function get_config($post_id) {
30 30
 		$config = new Config();
31 31
 
32
-		$config->post_id                  = intval( $post_id );
33
-		$config->mode                     = $this->get_meta( $post_id, 'mode' );
34
-		$config->refresh_token            = $this->get_meta( $post_id, 'omnikassa_2_refresh_token' );
35
-		$config->signing_key              = $this->get_meta( $post_id, 'omnikassa_2_signing_key' );
36
-		$config->access_token             = $this->get_meta( $post_id, 'omnikassa_2_access_token' );
37
-		$config->access_token_valid_until = $this->get_meta( $post_id, 'omnikassa_2_access_token_valid_until' );
38
-		$config->order_id                 = $this->get_meta( $post_id, 'omnikassa_2_order_id' );
32
+		$config->post_id                  = intval($post_id);
33
+		$config->mode                     = $this->get_meta($post_id, 'mode');
34
+		$config->refresh_token            = $this->get_meta($post_id, 'omnikassa_2_refresh_token');
35
+		$config->signing_key              = $this->get_meta($post_id, 'omnikassa_2_signing_key');
36
+		$config->access_token             = $this->get_meta($post_id, 'omnikassa_2_access_token');
37
+		$config->access_token_valid_until = $this->get_meta($post_id, 'omnikassa_2_access_token_valid_until');
38
+		$config->order_id                 = $this->get_meta($post_id, 'omnikassa_2_order_id');
39 39
 
40 40
 		return $config;
41 41
 	}
Please login to merge, or discard this patch.
src/Gateway.php 1 patch
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -35,23 +35,23 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param Config $config Config.
37 37
 	 */
38
-	public function __construct( Config $config ) {
39
-		parent::__construct( $config );
38
+	public function __construct(Config $config) {
39
+		parent::__construct($config);
40 40
 
41
-		$this->set_method( self::METHOD_HTTP_REDIRECT );
41
+		$this->set_method(self::METHOD_HTTP_REDIRECT);
42 42
 
43 43
 		// Client.
44 44
 		$this->client = new Client();
45 45
 
46 46
 		$url = Client::URL_PRODUCTION;
47 47
 
48
-		if ( self::MODE_TEST === $config->mode ) {
48
+		if (self::MODE_TEST === $config->mode) {
49 49
 			$url = Client::URL_SANDBOX;
50 50
 		}
51 51
 
52
-		$this->client->set_url( $url );
53
-		$this->client->set_refresh_token( $config->refresh_token );
54
-		$this->client->set_signing_key( $config->signing_key );
52
+		$this->client->set_url($url);
53
+		$this->client->set_refresh_token($config->refresh_token);
54
+		$this->client->set_signing_key($config->signing_key);
55 55
 	}
56 56
 
57 57
 	/**
@@ -76,53 +76,53 @@  discard block
 block discarded – undo
76 76
 	 *
77 77
 	 * @param Payment $payment Payment.
78 78
 	 */
79
-	public function start( Payment $payment ) {
79
+	public function start(Payment $payment) {
80 80
 		// Merchant order ID.
81
-		$merchant_order_id = $payment->format_string( $this->config->order_id );
81
+		$merchant_order_id = $payment->format_string($this->config->order_id);
82 82
 
83
-		$payment->set_meta( 'omnikassa_2_merchant_order_id', $merchant_order_id );
83
+		$payment->set_meta('omnikassa_2_merchant_order_id', $merchant_order_id);
84 84
 
85 85
 		// New order.
86 86
 		$order = new Order(
87 87
 			$merchant_order_id,
88 88
 			new Money(
89 89
 				$payment->get_currency(),
90
-				Core_Util::amount_to_cents( $payment->get_amount()->get_amount() )
90
+				Core_Util::amount_to_cents($payment->get_amount()->get_amount())
91 91
 			),
92 92
 			$payment->get_return_url()
93 93
 		);
94 94
 
95
-		$order->set_description( $payment->get_description() );
96
-		$order->set_language( $payment->get_language() );
95
+		$order->set_description($payment->get_description());
96
+		$order->set_language($payment->get_language());
97 97
 
98 98
 		// Payment brand.
99
-		$payment_brand = PaymentBrands::transform( $payment->get_method() );
99
+		$payment_brand = PaymentBrands::transform($payment->get_method());
100 100
 
101
-		$order->set_payment_brand( $payment_brand );
101
+		$order->set_payment_brand($payment_brand);
102 102
 
103
-		if ( null !== $payment_brand ) {
103
+		if (null !== $payment_brand) {
104 104
 			// Payment brand force should only be set if payment brand is not empty.
105
-			$order->set_payment_brand_force( PaymentBrandForce::FORCE_ONCE );
105
+			$order->set_payment_brand_force(PaymentBrandForce::FORCE_ONCE);
106 106
 		}
107 107
 
108 108
 		// Maybe update access token.
109 109
 		$this->maybe_update_access_token();
110 110
 
111 111
 		// Handle errors.
112
-		if ( $this->get_client_error() ) {
112
+		if ($this->get_client_error()) {
113 113
 			return;
114 114
 		}
115 115
 
116 116
 		// Announce order.
117
-		$result = $this->client->order_announce( $this->config, $order );
117
+		$result = $this->client->order_announce($this->config, $order);
118 118
 
119 119
 		// Handle errors.
120
-		if ( $this->get_client_error() ) {
120
+		if ($this->get_client_error()) {
121 121
 			return;
122 122
 		}
123 123
 
124
-		if ( $result ) {
125
-			$payment->set_action_url( $result->redirectUrl );
124
+		if ($result) {
125
+			$payment->set_action_url($result->redirectUrl);
126 126
 		}
127 127
 	}
128 128
 
@@ -131,45 +131,45 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @param Payment $payment Payment.
133 133
 	 */
134
-	public function update_status( Payment $payment ) {
135
-		if ( ! ReturnParameters::contains( $_GET ) ) { // WPCS: CSRF ok.
134
+	public function update_status(Payment $payment) {
135
+		if ( ! ReturnParameters::contains($_GET)) { // WPCS: CSRF ok.
136 136
 			return;
137 137
 		}
138 138
 
139
-		$parameters = ReturnParameters::from_array( $_GET ); // WPCS: CSRF ok.
139
+		$parameters = ReturnParameters::from_array($_GET); // WPCS: CSRF ok.
140 140
 
141 141
 		// Note.
142 142
 		$note_values = array(
143 143
 			'order_id'  => $parameters->get_order_id(),
144 144
 			'status'    => $parameters->get_status(),
145 145
 			'signature' => $parameters->get_signature(),
146
-			'valid'     => $parameters->is_valid( $this->config->signing_key ) ? 'true' : 'false',
146
+			'valid'     => $parameters->is_valid($this->config->signing_key) ? 'true' : 'false',
147 147
 		);
148 148
 
149 149
 		$note = '';
150 150
 
151 151
 		$note .= '<p>';
152
-		$note .= __( 'OmniKassa 2.0 return URL requested:', 'pronamic_ideal' );
152
+		$note .= __('OmniKassa 2.0 return URL requested:', 'pronamic_ideal');
153 153
 		$note .= '</p>';
154 154
 
155 155
 		$note .= '<dl>';
156 156
 
157
-		foreach ( $note_values as $key => $value ) {
158
-			$note .= sprintf( '<dt>%s</dt>', esc_html( $key ) );
159
-			$note .= sprintf( '<dd>%s</dd>', esc_html( $value ) );
157
+		foreach ($note_values as $key => $value) {
158
+			$note .= sprintf('<dt>%s</dt>', esc_html($key));
159
+			$note .= sprintf('<dd>%s</dd>', esc_html($value));
160 160
 		}
161 161
 
162 162
 		$note .= '</dl>';
163 163
 
164
-		$payment->add_note( $note );
164
+		$payment->add_note($note);
165 165
 
166 166
 		// Validate.
167
-		if ( ! $parameters->is_valid( $this->config->signing_key ) ) {
167
+		if ( ! $parameters->is_valid($this->config->signing_key)) {
168 168
 			return;
169 169
 		}
170 170
 
171 171
 		// Status.
172
-		$payment->set_status( Statuses::transform( $parameters->get_status() ) );
172
+		$payment->set_status(Statuses::transform($parameters->get_status()));
173 173
 	}
174 174
 
175 175
 	/**
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @return void
181 181
 	 */
182
-	public function handle_notification( Notification $notification ) {
183
-		if ( ! $notification->is_valid( $this->config->signing_key ) ) {
182
+	public function handle_notification(Notification $notification) {
183
+		if ( ! $notification->is_valid($this->config->signing_key)) {
184 184
 			return;
185 185
 		}
186 186
 
187
-		switch ( $notification->get_event_name() ) {
187
+		switch ($notification->get_event_name()) {
188 188
 			case 'merchant.order.status.changed':
189
-				$this->handle_merchant_order_status_changed( $notification );
189
+				$this->handle_merchant_order_status_changed($notification);
190 190
 		}
191 191
 	}
192 192
 
@@ -197,39 +197,39 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @return void
199 199
 	 */
200
-	private function handle_merchant_order_status_changed( Notification $notification ) {
200
+	private function handle_merchant_order_status_changed(Notification $notification) {
201 201
 		do {
202
-			$order_results = $this->client->get_order_results( $notification->get_authentication() );
202
+			$order_results = $this->client->get_order_results($notification->get_authentication());
203 203
 
204
-			if ( ! $order_results || $order_results->is_valid( $this->config->signing_key ) ) {
204
+			if ( ! $order_results || $order_results->is_valid($this->config->signing_key)) {
205 205
 				return;
206 206
 			}
207 207
 
208
-			foreach ( $order_results as $order_result ) {
209
-				$payment = get_pronamic_payment_by_meta( '_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id() );
208
+			foreach ($order_results as $order_result) {
209
+				$payment = get_pronamic_payment_by_meta('_pronamic_payment_omnikassa_2_merchant_order_id', $order_result->get_merchant_order_id());
210 210
 
211
-				if ( empty( $payment ) ) {
211
+				if (empty($payment)) {
212 212
 					continue;
213 213
 				}
214 214
 
215
-				$payment->set_transaction_id( $order_result->get_omnikassa_order_id() );
216
-				$payment->set_status( Statuses::transform( $order_result->get_order_status() ) );
215
+				$payment->set_transaction_id($order_result->get_omnikassa_order_id());
216
+				$payment->set_status(Statuses::transform($order_result->get_order_status()));
217 217
 
218 218
 				// Note.
219 219
 				$note = '';
220 220
 
221 221
 				$note .= '<p>';
222
-				$note .= __( 'OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal' );
222
+				$note .= __('OmniKassa 2.0 webhook URL requested:', 'pronamic_ideal');
223 223
 				$note .= '</p>';
224 224
 				$note .= '<pre>';
225
-				$note .= wp_json_encode( $order_result->get_json(), JSON_PRETTY_PRINT );
225
+				$note .= wp_json_encode($order_result->get_json(), JSON_PRETTY_PRINT);
226 226
 				$note .= '</pre>';
227 227
 
228
-				$payment->add_note( $note );
228
+				$payment->add_note($note);
229 229
 
230 230
 				$payment->save();
231 231
 			}
232
-		} while ( $order_results->more_available() );
232
+		} while ($order_results->more_available());
233 233
 	}
234 234
 
235 235
 	/**
@@ -238,20 +238,20 @@  discard block
 block discarded – undo
238 238
 	 * @return void
239 239
 	 */
240 240
 	private function maybe_update_access_token() {
241
-		if ( $this->config->is_access_token_valid() ) {
241
+		if ($this->config->is_access_token_valid()) {
242 242
 			return;
243 243
 		}
244 244
 
245 245
 		$data = $this->client->get_access_token_data();
246 246
 
247
-		if ( ! is_object( $data ) ) {
247
+		if ( ! is_object($data)) {
248 248
 			return;
249 249
 		}
250 250
 
251 251
 		$this->config->access_token             = $data->token;
252 252
 		$this->config->access_token_valid_until = $data->validUntil;
253 253
 
254
-		update_post_meta( $this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token );
254
+		update_post_meta($this->config->post_id, '_pronamic_gateway_omnikassa_2_access_token', $data->token);
255 255
 		update_post_meta(
256 256
 			$this->config->post_id,
257 257
 			'_pronamic_gateway_omnikassa_2_access_token_valid_until',
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	private function get_client_error() {
268 268
 		$error = $this->client->get_error();
269 269
 
270
-		if ( is_wp_error( $error ) ) {
270
+		if (is_wp_error($error)) {
271 271
 			$this->error = $error;
272 272
 
273 273
 			return $error;
Please login to merge, or discard this patch.