Passed
Push — develop ( 947370...c7f45f )
by Reüel
04:28
created
src/Extension.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
 	 */
46 46
 	public function __construct() {
47 47
 		// @see https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/lib/MeprGatewayFactory.php#L48-50
48
-		add_filter( 'mepr-gateway-paths', array( $this, 'gateway_paths' ) );
48
+		add_filter('mepr-gateway-paths', array($this, 'gateway_paths'));
49 49
 
50
-		add_filter( 'pronamic_payment_redirect_url_' . self::SLUG, array( __CLASS__, 'redirect_url' ), 10, 2 );
51
-		add_action( 'pronamic_payment_status_update_' . self::SLUG, array( __CLASS__, 'status_update' ), 10, 1 );
50
+		add_filter('pronamic_payment_redirect_url_' . self::SLUG, array(__CLASS__, 'redirect_url'), 10, 2);
51
+		add_action('pronamic_payment_status_update_' . self::SLUG, array(__CLASS__, 'status_update'), 10, 1);
52 52
 
53
-		add_filter( 'pronamic_payment_source_text_' . self::SLUG, array( __CLASS__, 'source_text' ), 10, 2 );
54
-		add_filter( 'pronamic_payment_source_description_' . self::SLUG, array( __CLASS__, 'source_description' ), 10, 2 );
55
-		add_filter( 'pronamic_payment_source_url_' . self::SLUG, array( __CLASS__, 'source_url' ), 10, 2 );
56
-		add_filter( 'pronamic_subscription_source_text_' . self::SLUG, array( __CLASS__, 'subscription_source_text' ), 10, 2 );
57
-		add_filter( 'pronamic_subscription_source_description_' . self::SLUG, array( __CLASS__, 'subscription_source_description' ), 10, 2 );
58
-		add_filter( 'pronamic_subscription_source_url_' . self::SLUG, array( __CLASS__, 'subscription_source_url' ), 10, 2 );
53
+		add_filter('pronamic_payment_source_text_' . self::SLUG, array(__CLASS__, 'source_text'), 10, 2);
54
+		add_filter('pronamic_payment_source_description_' . self::SLUG, array(__CLASS__, 'source_description'), 10, 2);
55
+		add_filter('pronamic_payment_source_url_' . self::SLUG, array(__CLASS__, 'source_url'), 10, 2);
56
+		add_filter('pronamic_subscription_source_text_' . self::SLUG, array(__CLASS__, 'subscription_source_text'), 10, 2);
57
+		add_filter('pronamic_subscription_source_description_' . self::SLUG, array(__CLASS__, 'subscription_source_description'), 10, 2);
58
+		add_filter('pronamic_subscription_source_url_' . self::SLUG, array(__CLASS__, 'subscription_source_url'), 10, 2);
59 59
 
60
-		add_action( 'mepr_subscription_pre_delete', array( $this, 'subscription_pre_delete' ), 10, 1 );
60
+		add_action('mepr_subscription_pre_delete', array($this, 'subscription_pre_delete'), 10, 1);
61 61
 
62
-		add_action( 'mepr_subscription_transition_status', array( $this, 'memberpress_subscription_transition_status' ), 10, 3 );
62
+		add_action('mepr_subscription_transition_status', array($this, 'memberpress_subscription_transition_status'), 10, 3);
63 63
 	}
64 64
 
65 65
 	/**
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 	 * @param array $paths Array with gateway paths.
71 71
 	 * @return array
72 72
 	 */
73
-	public function gateway_paths( $paths ) {
74
-		$paths[] = dirname( __FILE__ ) . '/../gateways/';
73
+	public function gateway_paths($paths) {
74
+		$paths[] = dirname(__FILE__) . '/../gateways/';
75 75
 
76 76
 		return $paths;
77 77
 	}
@@ -86,14 +86,14 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @return string
88 88
 	 */
89
-	public static function redirect_url( $url, Payment $payment ) {
89
+	public static function redirect_url($url, Payment $payment) {
90 90
 		global $transaction;
91 91
 
92 92
 		$transaction_id = $payment->get_source_id();
93 93
 
94
-		$transaction = new MeprTransaction( $transaction_id );
94
+		$transaction = new MeprTransaction($transaction_id);
95 95
 
96
-		switch ( $payment->get_status() ) {
96
+		switch ($payment->get_status()) {
97 97
 			case Statuses::CANCELLED:
98 98
 			case Statuses::EXPIRED:
99 99
 			case Statuses::FAILURE:
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 					array(
104 104
 						'action'   => 'payment_form',
105 105
 						'txn'      => $transaction->trans_num,
106
-						'_wpnonce' => wp_create_nonce( 'mepr_payment_form' ),
106
+						'_wpnonce' => wp_create_nonce('mepr_payment_form'),
107 107
 					),
108 108
 					$product->url()
109 109
 				);
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 				// @see https://gitlab.com/pronamic/memberpress/blob/1.2.4/app/models/MeprOptions.php#L768-782
114 114
 				$mepr_options = MeprOptions::fetch();
115 115
 
116
-				$product         = new MeprProduct( $transaction->product_id );
117
-				$sanitized_title = sanitize_title( $product->post_title );
116
+				$product         = new MeprProduct($transaction->product_id);
117
+				$sanitized_title = sanitize_title($product->post_title);
118 118
 
119 119
 				$args = array(
120 120
 					'membership_id' => $product->ID,
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 					'trans_num'     => $transaction->trans_num,
123 123
 				);
124 124
 
125
-				$url = $mepr_options->thankyou_page_url( http_build_query( $args ) );
125
+				$url = $mepr_options->thankyou_page_url(http_build_query($args));
126 126
 
127 127
 				break;
128 128
 			case Statuses::OPEN:
@@ -140,26 +140,26 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @param Payment $payment The payment whose status is updated.
142 142
 	 */
143
-	public static function status_update( Payment $payment ) {
143
+	public static function status_update(Payment $payment) {
144 144
 		$transaction_id = $payment->get_source_id();
145 145
 
146
-		$transaction = new MeprTransaction( $transaction_id );
146
+		$transaction = new MeprTransaction($transaction_id);
147 147
 
148
-		if ( $payment->get_recurring() ) {
148
+		if ($payment->get_recurring()) {
149 149
 			$subscription = $transaction->subscription();
150 150
 
151
-			if ( empty( $subscription ) || empty( $subscription->id ) ) {
151
+			if (empty($subscription) || empty($subscription->id)) {
152 152
 				$subscription_id = $payment->get_subscription()->get_source_id();
153 153
 
154
-				$subscription = new MeprSubscription( $subscription_id );
154
+				$subscription = new MeprSubscription($subscription_id);
155 155
 			}
156 156
 
157 157
 			// Same source ID and first transaction ID for recurring payment means we need to add a new transaction.
158
-			if ( $payment->get_source_id() === $subscription->id ) {
158
+			if ($payment->get_source_id() === $subscription->id) {
159 159
 				// First transaction.
160 160
 				$first_txn = $subscription->first_txn();
161 161
 
162
-				if ( false === $first_txn || ! ( $first_txn instanceof MeprTransaction ) ) {
162
+				if (false === $first_txn || ! ($first_txn instanceof MeprTransaction)) {
163 163
 					$first_txn             = new MeprTransaction();
164 164
 					$first_txn->user_id    = $subscription->user_id;
165 165
 					$first_txn->product_id = $subscription->product_id;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 				// Transaction number.
171 171
 				$trans_num = $payment->get_transaction_id();
172 172
 
173
-				if ( empty( $trans_num ) ) {
173
+				if (empty($trans_num)) {
174 174
 					$trans_num = uniqid();
175 175
 				}
176 176
 
@@ -186,28 +186,28 @@  discard block
 block discarded – undo
186 186
 				$transaction->status          = MeprTransaction::$pending_str;
187 187
 				$transaction->subscription_id = $subscription->id;
188 188
 
189
-				$transaction->set_gross( $payment->get_amount()->get_amount() );
189
+				$transaction->set_gross($payment->get_amount()->get_amount());
190 190
 
191 191
 				$transaction->store();
192 192
 
193 193
 				// Set source ID.
194
-				$payment->set_meta( 'source_id', $transaction->id );
194
+				$payment->set_meta('source_id', $transaction->id);
195 195
 
196 196
 				$payment->source_id = $transaction->id;
197 197
 			}
198 198
 		}
199 199
 
200
-		$should_update = ! MemberPress::transaction_has_status( $transaction, array(
200
+		$should_update = ! MemberPress::transaction_has_status($transaction, array(
201 201
 			MeprTransaction::$failed_str,
202 202
 			MeprTransaction::$complete_str,
203
-		) );
203
+		));
204 204
 
205
-		if ( $should_update ) {
205
+		if ($should_update) {
206 206
 			$gateway = new Gateway();
207 207
 
208 208
 			$gateway->mp_txn = $transaction;
209 209
 
210
-			switch ( $payment->get_status() ) {
210
+			switch ($payment->get_status()) {
211 211
 				case Statuses::CANCELLED:
212 212
 				case Statuses::EXPIRED:
213 213
 				case Statuses::FAILURE:
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 
216 216
 					break;
217 217
 				case Statuses::SUCCESS:
218
-					if ( $payment->get_recurring() ) {
218
+					if ($payment->get_recurring()) {
219 219
 						$gateway->record_subscription_payment();
220 220
 					} else {
221 221
 						$gateway->record_payment();
@@ -234,25 +234,25 @@  discard block
 block discarded – undo
234 234
 	 *
235 235
 	 * @param int $subscription_id MemberPress subscription id.
236 236
 	 */
237
-	public function subscription_pre_delete( $subscription_id ) {
238
-		$subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $subscription_id );
237
+	public function subscription_pre_delete($subscription_id) {
238
+		$subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $subscription_id);
239 239
 
240
-		if ( ! $subscription ) {
240
+		if ( ! $subscription) {
241 241
 			return;
242 242
 		}
243 243
 
244 244
 		// Add note.
245 245
 		$note = sprintf(
246 246
 			/* translators: %s: MemberPress */
247
-			__( '%s subscription deleted.', 'pronamic_ideal' ),
248
-			__( 'MemberPress', 'pronamic_ideal' )
247
+			__('%s subscription deleted.', 'pronamic_ideal'),
248
+			__('MemberPress', 'pronamic_ideal')
249 249
 		);
250 250
 
251
-		$subscription->add_note( $note );
251
+		$subscription->add_note($note);
252 252
 
253 253
 		// The status of canceled or completed subscriptions will not be changed automatically.
254
-		if ( ! in_array( $subscription->get_status(), array( Statuses::CANCELLED, Statuses::COMPLETED ), true ) ) {
255
-			$subscription->set_status( Statuses::CANCELLED );
254
+		if ( ! in_array($subscription->get_status(), array(Statuses::CANCELLED, Statuses::COMPLETED), true)) {
255
+			$subscription->set_status(Statuses::CANCELLED);
256 256
 
257 257
 			$subscription->save();
258 258
 		}
@@ -266,18 +266,18 @@  discard block
 block discarded – undo
266 266
 	 *
267 267
 	 * @return string
268 268
 	 */
269
-	public static function source_text( $text, Payment $payment ) {
270
-		$text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />';
269
+	public static function source_text($text, Payment $payment) {
270
+		$text = __('MemberPress', 'pronamic_ideal') . '<br />';
271 271
 
272 272
 		$text .= sprintf(
273 273
 			'<a href="%s">%s</a>',
274
-			add_query_arg( array(
274
+			add_query_arg(array(
275 275
 				'page'   => 'memberpress-trans',
276 276
 				'action' => 'edit',
277 277
 				'id'     => $payment->source_id,
278
-			), admin_url( 'admin.php' ) ),
278
+			), admin_url('admin.php')),
279 279
 			/* translators: %s: payment source id */
280
-			sprintf( __( 'Transaction %s', 'pronamic_ideal' ), $payment->source_id )
280
+			sprintf(__('Transaction %s', 'pronamic_ideal'), $payment->source_id)
281 281
 		);
282 282
 
283 283
 		return $text;
@@ -291,17 +291,17 @@  discard block
 block discarded – undo
291 291
 	 *
292 292
 	 * @return string
293 293
 	 */
294
-	public static function subscription_source_text( $text, Subscription $subscription ) {
295
-		$text = __( 'MemberPress', 'pronamic_ideal' ) . '<br />';
294
+	public static function subscription_source_text($text, Subscription $subscription) {
295
+		$text = __('MemberPress', 'pronamic_ideal') . '<br />';
296 296
 
297 297
 		$text .= sprintf(
298 298
 			'<a href="%s">%s</a>',
299
-			add_query_arg( array(
299
+			add_query_arg(array(
300 300
 				'page'         => 'memberpress-subscriptions',
301 301
 				'subscription' => $subscription->source_id,
302
-			), admin_url( 'admin.php' ) ),
302
+			), admin_url('admin.php')),
303 303
 			/* translators: %s: payment source id */
304
-			sprintf( __( 'Subscription %s', 'pronamic_ideal' ), $subscription->source_id )
304
+			sprintf(__('Subscription %s', 'pronamic_ideal'), $subscription->source_id)
305 305
 		);
306 306
 
307 307
 		return $text;
@@ -315,8 +315,8 @@  discard block
 block discarded – undo
315 315
 	 *
316 316
 	 * @return string
317 317
 	 */
318
-	public static function source_description( $description, Payment $payment ) {
319
-		return __( 'MemberPress Transaction', 'pronamic_ideal' );
318
+	public static function source_description($description, Payment $payment) {
319
+		return __('MemberPress Transaction', 'pronamic_ideal');
320 320
 	}
321 321
 
322 322
 	/**
@@ -327,8 +327,8 @@  discard block
 block discarded – undo
327 327
 	 *
328 328
 	 * @return string
329 329
 	 */
330
-	public static function subscription_source_description( $description, Subscription $subscription ) {
331
-		return __( 'MemberPress Subscription', 'pronamic_ideal' );
330
+	public static function subscription_source_description($description, Subscription $subscription) {
331
+		return __('MemberPress Subscription', 'pronamic_ideal');
332 332
 	}
333 333
 
334 334
 	/**
@@ -339,12 +339,12 @@  discard block
 block discarded – undo
339 339
 	 *
340 340
 	 * @return string
341 341
 	 */
342
-	public static function source_url( $url, Payment $payment ) {
343
-		$url = add_query_arg( array(
342
+	public static function source_url($url, Payment $payment) {
343
+		$url = add_query_arg(array(
344 344
 			'page'   => 'memberpress-trans',
345 345
 			'action' => 'edit',
346 346
 			'id'     => $payment->source_id,
347
-		), admin_url( 'admin.php' ) );
347
+		), admin_url('admin.php'));
348 348
 
349 349
 		return $url;
350 350
 	}
@@ -357,11 +357,11 @@  discard block
 block discarded – undo
357 357
 	 *
358 358
 	 * @return string
359 359
 	 */
360
-	public static function subscription_source_url( $url, Subscription $subscription ) {
361
-		$url = add_query_arg( array(
360
+	public static function subscription_source_url($url, Subscription $subscription) {
361
+		$url = add_query_arg(array(
362 362
 			'page'         => 'memberpress-subscriptions',
363 363
 			'subscription' => $subscription->source_id,
364
-		), admin_url( 'admin.php' ) );
364
+		), admin_url('admin.php'));
365 365
 
366 366
 		return $url;
367 367
 	}
@@ -377,16 +377,16 @@  discard block
 block discarded – undo
377 377
 	 * @param string           $status_new               New status identifier.
378 378
 	 * @param MeprSubscription $memberpress_subscription MemberPress subscription object.
379 379
 	 */
380
-	public function memberpress_subscription_transition_status( $status_old, $status_new, $memberpress_subscription ) {
381
-		$subscription = get_pronamic_subscription_by_meta( '_pronamic_subscription_source_id', $memberpress_subscription->id );
380
+	public function memberpress_subscription_transition_status($status_old, $status_new, $memberpress_subscription) {
381
+		$subscription = get_pronamic_subscription_by_meta('_pronamic_subscription_source_id', $memberpress_subscription->id);
382 382
 
383
-		if ( empty( $subscription ) ) {
383
+		if (empty($subscription)) {
384 384
 			return;
385 385
 		}
386 386
 
387
-		$status = SubscriptionStatuses::transform( $status_new );
387
+		$status = SubscriptionStatuses::transform($status_new);
388 388
 
389
-		$subscription->set_status( $status );
389
+		$subscription->set_status($status);
390 390
 
391 391
 		$subscription->save();
392 392
 	}
Please login to merge, or discard this patch.