Passed
Branch — develop (649d49)
by Remco
06:34
created
views/redirect-via-html.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,11 +12,11 @@  discard block
 block discarded – undo
12 12
 
13 13
 use Pronamic\WordPress\Pay\Plugin;
14 14
 
15
-$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
15
+$min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
16 16
 
17 17
 wp_register_style(
18 18
 	'pronamic-pay-redirect',
19
-	plugins_url( 'css/redirect' . $min . '.css', Plugin::$file ),
19
+	plugins_url('css/redirect' . $min . '.css', Plugin::$file),
20 20
 	array(),
21 21
 	$pronamic_ideal->get_version()
22 22
 );
@@ -26,18 +26,18 @@  discard block
 block discarded – undo
26 26
 
27 27
 <html <?php language_attributes(); ?>>
28 28
 	<head>
29
-		<meta charset="<?php bloginfo( 'charset' ); ?>" />
29
+		<meta charset="<?php bloginfo('charset'); ?>" />
30 30
 
31
-		<title><?php esc_html_e( 'Redirecting…', 'pronamic_ideal' ); ?></title>
31
+		<title><?php esc_html_e('Redirecting…', 'pronamic_ideal'); ?></title>
32 32
 
33
-		<?php wp_print_styles( 'pronamic-pay-redirect' ); ?>
33
+		<?php wp_print_styles('pronamic-pay-redirect'); ?>
34 34
 	</head>
35 35
 
36 36
 	<?php
37 37
 
38 38
 	$auto_submit = true;
39 39
 
40
-	if ( defined( 'PRONAMIC_PAY_DEBUG' ) && PRONAMIC_PAY_DEBUG ) {
40
+	if (defined('PRONAMIC_PAY_DEBUG') && PRONAMIC_PAY_DEBUG) {
41 41
 		$auto_submit = false;
42 42
 	}
43 43
 
@@ -45,22 +45,22 @@  discard block
 block discarded – undo
45 45
 
46 46
 	?>
47 47
 
48
-	<body onload="<?php esc_attr( $onload ); ?>">
48
+	<body onload="<?php esc_attr($onload); ?>">
49 49
 		<div class="pronamic-pay-redirect-page">
50 50
 			<div class="pronamic-pay-redirect-container">
51
-				<h1><?php esc_html_e( 'Redirecting…', 'pronamic_ideal' ); ?></h1>
51
+				<h1><?php esc_html_e('Redirecting…', 'pronamic_ideal'); ?></h1>
52 52
 
53 53
 				<p>
54
-					<?php esc_html_e( 'You will be automatically redirected to the online payment environment.', 'pronamic_ideal' ); ?>
54
+					<?php esc_html_e('You will be automatically redirected to the online payment environment.', 'pronamic_ideal'); ?>
55 55
 				</p>
56 56
 
57 57
 				<p>
58
-					<?php esc_html_e( 'Please click the button below if you are not automatically redirected.', 'pronamic_ideal' ); ?>
58
+					<?php esc_html_e('Please click the button below if you are not automatically redirected.', 'pronamic_ideal'); ?>
59 59
 				</p>
60 60
 
61 61
 				<?php
62 62
 
63
-				echo $this->get_form_html( $payment, $auto_submit ); // WPCS: XSS ok.
63
+				echo $this->get_form_html($payment, $auto_submit); // WPCS: XSS ok.
64 64
 
65 65
 				?>
66 66
 			</div>
Please login to merge, or discard this patch.
views/error.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -8,45 +8,45 @@  discard block
 block discarded – undo
8 8
  * @package   Pronamic\WordPress\Pay
9 9
  */
10 10
 
11
-if ( is_wp_error( $error ) ) : ?>
11
+if (is_wp_error($error)) : ?>
12 12
 
13 13
 	<div class="error">
14 14
 		<?php
15 15
 
16
-		foreach ( $error->get_error_codes() as $code ) {
16
+		foreach ($error->get_error_codes() as $code) {
17 17
 			?>
18 18
 			<dl>
19
-				<dt><?php esc_html_e( 'Code', 'pronamic_ideal' ); ?></dt>
20
-				<dd><?php echo esc_html( $code ); ?></dd>
19
+				<dt><?php esc_html_e('Code', 'pronamic_ideal'); ?></dt>
20
+				<dd><?php echo esc_html($code); ?></dd>
21 21
 
22
-				<dt><?php esc_html_e( 'Message', 'pronamic_ideal' ); ?></dt>
23
-				<dd><?php echo esc_html( $error->get_error_message( $code ) ); ?></dd>
22
+				<dt><?php esc_html_e('Message', 'pronamic_ideal'); ?></dt>
23
+				<dd><?php echo esc_html($error->get_error_message($code)); ?></dd>
24 24
 			</dl>
25 25
 
26 26
 			<?php
27 27
 
28
-			if ( 'ideal_advanced_error' === $code ) {
29
-				$ideal_error = $error->get_error_data( $code );
28
+			if ('ideal_advanced_error' === $code) {
29
+				$ideal_error = $error->get_error_data($code);
30 30
 
31
-				if ( $ideal_error instanceof Pronamic_Gateways_IDealAdvanced_Error ) :
31
+				if ($ideal_error instanceof Pronamic_Gateways_IDealAdvanced_Error) :
32 32
 
33 33
 					?>
34 34
 
35 35
 					<dl>
36
-						<dt><?php esc_html_e( 'Code', 'pronamic_ideal' ); ?></dt>
37
-						<dd><?php echo esc_html( $ideal_error->get_code() ); ?></dd>
36
+						<dt><?php esc_html_e('Code', 'pronamic_ideal'); ?></dt>
37
+						<dd><?php echo esc_html($ideal_error->get_code()); ?></dd>
38 38
 
39
-						<dt><?php esc_html_e( 'Message', 'pronamic_ideal' ); ?></dt>
40
-						<dd><?php echo esc_html( $ideal_error->get_message() ); ?></dd>
39
+						<dt><?php esc_html_e('Message', 'pronamic_ideal'); ?></dt>
40
+						<dd><?php echo esc_html($ideal_error->get_message()); ?></dd>
41 41
 
42
-						<dt><?php esc_html_e( 'Detail', 'pronamic_ideal' ); ?></dt>
43
-						<dd><?php echo esc_html( $ideal_error->get_detail() ); ?></dd>
42
+						<dt><?php esc_html_e('Detail', 'pronamic_ideal'); ?></dt>
43
+						<dd><?php echo esc_html($ideal_error->get_detail()); ?></dd>
44 44
 
45
-						<dt><?php esc_html_e( 'Suggested Action', 'pronamic_ideal' ); ?></dt>
46
-						<dd><?php echo esc_html( $ideal_error->get_suggested_action() ); ?></dd>
45
+						<dt><?php esc_html_e('Suggested Action', 'pronamic_ideal'); ?></dt>
46
+						<dd><?php echo esc_html($ideal_error->get_suggested_action()); ?></dd>
47 47
 
48
-						<dt><?php esc_html_e( 'Consumer Message', 'pronamic_ideal' ); ?></dt>
49
-						<dd><?php echo esc_html( $ideal_error->get_consumer_message() ); ?></dd>
48
+						<dt><?php esc_html_e('Consumer Message', 'pronamic_ideal'); ?></dt>
49
+						<dd><?php echo esc_html($ideal_error->get_consumer_message()); ?></dd>
50 50
 					</dl>
51 51
 
52 52
 					<?php
@@ -54,28 +54,28 @@  discard block
 block discarded – undo
54 54
 				endif;
55 55
 			}
56 56
 
57
-			if ( 'ideal_advanced_v3_error' === $code ) {
58
-				$ideal_error = $error->get_error_data( $code );
57
+			if ('ideal_advanced_v3_error' === $code) {
58
+				$ideal_error = $error->get_error_data($code);
59 59
 
60
-				if ( $ideal_error instanceof Pronamic_Gateways_IDealAdvancedV3_Error ) :
60
+				if ($ideal_error instanceof Pronamic_Gateways_IDealAdvancedV3_Error) :
61 61
 
62 62
 					?>
63 63
 
64 64
 					<dl>
65
-						<dt><?php esc_html_e( 'Code', 'pronamic_ideal' ); ?></dt>
66
-						<dd><?php echo esc_html( $ideal_error->get_code() ); ?></dd>
65
+						<dt><?php esc_html_e('Code', 'pronamic_ideal'); ?></dt>
66
+						<dd><?php echo esc_html($ideal_error->get_code()); ?></dd>
67 67
 
68
-						<dt><?php esc_html_e( 'Message', 'pronamic_ideal' ); ?></dt>
69
-						<dd><?php echo esc_html( $ideal_error->get_message() ); ?></dd>
68
+						<dt><?php esc_html_e('Message', 'pronamic_ideal'); ?></dt>
69
+						<dd><?php echo esc_html($ideal_error->get_message()); ?></dd>
70 70
 
71
-						<dt><?php esc_html_e( 'Detail', 'pronamic_ideal' ); ?></dt>
72
-						<dd><?php echo esc_html( $ideal_error->get_detail() ); ?></dd>
71
+						<dt><?php esc_html_e('Detail', 'pronamic_ideal'); ?></dt>
72
+						<dd><?php echo esc_html($ideal_error->get_detail()); ?></dd>
73 73
 
74
-						<dt><?php esc_html_e( 'Suggested Action', 'pronamic_ideal' ); ?></dt>
75
-						<dd><?php echo esc_html( $ideal_error->get_suggested_action() ); ?></dd>
74
+						<dt><?php esc_html_e('Suggested Action', 'pronamic_ideal'); ?></dt>
75
+						<dd><?php echo esc_html($ideal_error->get_suggested_action()); ?></dd>
76 76
 
77
-						<dt><?php esc_html_e( 'Consumer Message', 'pronamic_ideal' ); ?></dt>
78
-						<dd><?php echo esc_html( $ideal_error->get_consumer_message() ); ?></dd>
77
+						<dt><?php esc_html_e('Consumer Message', 'pronamic_ideal'); ?></dt>
78
+						<dd><?php echo esc_html($ideal_error->get_consumer_message()); ?></dd>
79 79
 					</dl>
80 80
 
81 81
 					<?php
Please login to merge, or discard this patch.
classes/Currency.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,24 +25,24 @@
 block discarded – undo
25 25
 	 * @param string $code Code to convert.
26 26
 	 * @return string
27 27
 	 */
28
-	public static function transform_code_to_number( $code ) {
28
+	public static function transform_code_to_number($code) {
29 29
 		$currencies = array();
30 30
 
31
-		$file = dirname( Plugin::$file ) . '/other/dl_iso_table_a1.xml';
31
+		$file = dirname(Plugin::$file) . '/other/dl_iso_table_a1.xml';
32 32
 
33
-		$xml = simplexml_load_file( $file );
33
+		$xml = simplexml_load_file($file);
34 34
 
35
-		foreach ( $xml->ISO_CURRENCY as $currency ) {
36
-			$alphabetic_code = Security::filter( $currency->ALPHABETIC_CODE );
37
-			$numeric_code    = Security::filter( $currency->NUMERIC_CODE );
35
+		foreach ($xml->ISO_CURRENCY as $currency) {
36
+			$alphabetic_code = Security::filter($currency->ALPHABETIC_CODE);
37
+			$numeric_code    = Security::filter($currency->NUMERIC_CODE);
38 38
 
39
-			$currencies[ $alphabetic_code ] = $numeric_code;
39
+			$currencies[$alphabetic_code] = $numeric_code;
40 40
 		}
41 41
 
42 42
 		$number = null;
43 43
 
44
-		if ( isset( $currencies[ $code ] ) ) {
45
-			$number = $currencies[ $code ];
44
+		if (isset($currencies[$code])) {
45
+			$number = $currencies[$code];
46 46
 		}
47 47
 
48 48
 		return $number;
Please login to merge, or discard this patch.
classes/CreditCard.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @param string $number Number.
77 77
 	 */
78
-	public function set_number( $number ) {
78
+	public function set_number($number) {
79 79
 		$this->number = $number;
80 80
 	}
81 81
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @param int $month Month.
95 95
 	 */
96
-	public function set_expiration_month( $month ) {
96
+	public function set_expiration_month($month) {
97 97
 		$this->expiration_month = $month;
98 98
 	}
99 99
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @param int $year Year.
113 113
 	 */
114
-	public function set_expiration_year( $year ) {
114
+	public function set_expiration_year($year) {
115 115
 		$this->expiration_year = $year;
116 116
 	}
117 117
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @return DateTime
122 122
 	 */
123 123
 	public function get_expiration_date() {
124
-		return new DateTime( '@' . gmmktime( 0, 0, 0, $this->expiration_month, 1, $this->expiration_year ) );
124
+		return new DateTime('@' . gmmktime(0, 0, 0, $this->expiration_month, 1, $this->expiration_year));
125 125
 	}
126 126
 
127 127
 	/**
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @param int $security_code Security code.
140 140
 	 */
141
-	public function set_security_code( $security_code ) {
141
+	public function set_security_code($security_code) {
142 142
 		$this->security_code = $security_code;
143 143
 	}
144 144
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @param string $name Name.
158 158
 	 */
159
-	public function set_name( $name ) {
159
+	public function set_name($name) {
160 160
 		$this->name = $name;
161 161
 	}
162 162
 }
Please login to merge, or discard this patch.
classes/Settings.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param Plugin $plugin The plugin.
31 31
 	 */
32
-	public function __construct( $plugin ) {
32
+	public function __construct($plugin) {
33 33
 		$this->plugin = $plugin;
34 34
 
35 35
 		// Actions.
36
-		add_action( 'load-options.php', array( $this, 'load_options_dont_trim_all_posted_values' ) );
36
+		add_action('load-options.php', array($this, 'load_options_dont_trim_all_posted_values'));
37 37
 
38
-		add_action( 'init', array( $this, 'init' ) );
38
+		add_action('init', array($this, 'init'));
39 39
 	}
40 40
 
41 41
 	/**
@@ -51,8 +51,8 @@  discard block
 block discarded – undo
51 51
 			'pronamic_pay_decimal_sep',
52 52
 		);
53 53
 
54
-		foreach ( $no_trim_options as $option ) {
55
-			add_filter( 'sanitize_option_' . $option, array( $this, 'sanitize_option_dont_trim_posted_value' ), 10, 2 );
54
+		foreach ($no_trim_options as $option) {
55
+			add_filter('sanitize_option_' . $option, array($this, 'sanitize_option_dont_trim_posted_value'), 10, 2);
56 56
 		}
57 57
 	}
58 58
 
@@ -63,17 +63,17 @@  discard block
 block discarded – undo
63 63
 	 * @param string $option The option name to sanitize.
64 64
 	 * @return string
65 65
 	 */
66
-	public function sanitize_option_dont_trim_posted_value( $value, $option ) {
66
+	public function sanitize_option_dont_trim_posted_value($value, $option) {
67 67
 		$screen = get_current_screen();
68 68
 
69
-		if ( 'options' !== $screen->id ) {
69
+		if ('options' !== $screen->id) {
70 70
 			return $value;
71 71
 		}
72 72
 
73 73
 		// @see https://github.com/WordPress/WordPress/blob/4.9/wp-admin/options.php#L203-L214
74
-		if ( isset( $_POST[ $option ] ) ) { // WPCS: CSRF ok.
75
-			$value = $_POST[ $option ]; // WPCS: CSRF ok.
76
-			$value = wp_unslash( $value );
74
+		if (isset($_POST[$option])) { // WPCS: CSRF ok.
75
+			$value = $_POST[$option]; // WPCS: CSRF ok.
76
+			$value = wp_unslash($value);
77 77
 		}
78 78
 
79 79
 		return $value;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		register_setting(
101 101
 			'pronamic_pay', 'pronamic_pay_config_id', array(
102 102
 				'type'              => 'integer',
103
-				'sanitize_callback' => array( $this, 'sanitize_published_post_id' ),
103
+				'sanitize_callback' => array($this, 'sanitize_published_post_id'),
104 104
 			)
105 105
 		);
106 106
 
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 			)
145 145
 		);
146 146
 
147
-		foreach ( $this->plugin->get_pages() as $id => $label ) {
147
+		foreach ($this->plugin->get_pages() as $id => $label) {
148 148
 			register_setting(
149 149
 				'pronamic_pay', $id, array(
150 150
 					'type'              => 'integer',
151
-					'sanitize_callback' => array( $this, 'sanitize_published_post_id' ),
151
+					'sanitize_callback' => array($this, 'sanitize_published_post_id'),
152 152
 				)
153 153
 			);
154 154
 		}
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
 	 * @param string $value Check if the value is published post ID.
161 161
 	 * @return boolean True if post status is publish, false otherwise.
162 162
 	 */
163
-	public function sanitize_published_post_id( $value ) {
164
-		if ( 'publish' === get_post_status( $value ) ) {
163
+	public function sanitize_published_post_id($value) {
164
+		if ('publish' === get_post_status($value)) {
165 165
 			return $value;
166 166
 		}
167 167
 
Please login to merge, or discard this patch.
classes/Subscriptions/SubscriptionPostType.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 		 *
33 33
 		 * @see https://github.com/WordPress/WordPress/blob/4.0/wp-includes/post.php#L167
34 34
 		 */
35
-		add_action( 'init', array( $this, 'register_subscription_post_type' ), 0 ); // Highest priority.
36
-		add_action( 'init', array( $this, 'register_post_status' ), 9 );
35
+		add_action('init', array($this, 'register_subscription_post_type'), 0); // Highest priority.
36
+		add_action('init', array($this, 'register_post_status'), 9);
37 37
 	}
38 38
 
39 39
 	/**
@@ -44,23 +44,23 @@  discard block
 block discarded – undo
44 44
 	public function register_subscription_post_type() {
45 45
 		register_post_type(
46 46
 			'pronamic_pay_subscr', array(
47
-				'label'              => __( 'Subscriptions', 'pronamic_ideal' ),
47
+				'label'              => __('Subscriptions', 'pronamic_ideal'),
48 48
 				'labels'             => array(
49
-					'name'                  => __( 'Subscriptions', 'pronamic_ideal' ),
50
-					'singular_name'         => __( 'Subscription', 'pronamic_ideal' ),
51
-					'add_new'               => __( 'Add New', 'pronamic_ideal' ),
52
-					'add_new_item'          => __( 'Add New Subscription', 'pronamic_ideal' ),
53
-					'edit_item'             => __( 'Edit Subscription', 'pronamic_ideal' ),
54
-					'new_item'              => __( 'New Subscription', 'pronamic_ideal' ),
55
-					'all_items'             => __( 'All Subscriptions', 'pronamic_ideal' ),
56
-					'view_item'             => __( 'View Subscription', 'pronamic_ideal' ),
57
-					'search_items'          => __( 'Search Subscriptions', 'pronamic_ideal' ),
58
-					'not_found'             => __( 'No subscriptions found.', 'pronamic_ideal' ),
59
-					'not_found_in_trash'    => __( 'No subscriptions found in Trash.', 'pronamic_ideal' ),
60
-					'menu_name'             => __( 'Subscriptions', 'pronamic_ideal' ),
61
-					'filter_items_list'     => __( 'Filter subscriptions list', 'pronamic_ideal' ),
62
-					'items_list_navigation' => __( 'Subscriptions list navigation', 'pronamic_ideal' ),
63
-					'items_list'            => __( 'Subscriptions list', 'pronamic_ideal' ),
49
+					'name'                  => __('Subscriptions', 'pronamic_ideal'),
50
+					'singular_name'         => __('Subscription', 'pronamic_ideal'),
51
+					'add_new'               => __('Add New', 'pronamic_ideal'),
52
+					'add_new_item'          => __('Add New Subscription', 'pronamic_ideal'),
53
+					'edit_item'             => __('Edit Subscription', 'pronamic_ideal'),
54
+					'new_item'              => __('New Subscription', 'pronamic_ideal'),
55
+					'all_items'             => __('All Subscriptions', 'pronamic_ideal'),
56
+					'view_item'             => __('View Subscription', 'pronamic_ideal'),
57
+					'search_items'          => __('Search Subscriptions', 'pronamic_ideal'),
58
+					'not_found'             => __('No subscriptions found.', 'pronamic_ideal'),
59
+					'not_found_in_trash'    => __('No subscriptions found in Trash.', 'pronamic_ideal'),
60
+					'menu_name'             => __('Subscriptions', 'pronamic_ideal'),
61
+					'filter_items_list'     => __('Filter subscriptions list', 'pronamic_ideal'),
62
+					'items_list_navigation' => __('Subscriptions list navigation', 'pronamic_ideal'),
63
+					'items_list'            => __('Subscriptions list', 'pronamic_ideal'),
64 64
 				),
65 65
 				'public'             => false,
66 66
 				'publicly_queryable' => false,
@@ -86,67 +86,67 @@  discard block
 block discarded – undo
86 86
 		 */
87 87
 		register_post_status(
88 88
 			'subscr_pending', array(
89
-				'label'                     => _x( 'Pending', 'Subscription status', 'pronamic_ideal' ),
89
+				'label'                     => _x('Pending', 'Subscription status', 'pronamic_ideal'),
90 90
 				'public'                    => false,
91 91
 				'exclude_from_search'       => false,
92 92
 				'show_in_admin_all_list'    => true,
93 93
 				'show_in_admin_status_list' => true,
94
-				'label_count'               => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'pronamic_ideal' ),
94
+				'label_count'               => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'pronamic_ideal'),
95 95
 			)
96 96
 		);
97 97
 
98 98
 		register_post_status(
99 99
 			'subscr_cancelled', array(
100
-				'label'                     => _x( 'Cancelled', 'Subscription status', 'pronamic_ideal' ),
100
+				'label'                     => _x('Cancelled', 'Subscription status', 'pronamic_ideal'),
101 101
 				'public'                    => false,
102 102
 				'exclude_from_search'       => false,
103 103
 				'show_in_admin_all_list'    => true,
104 104
 				'show_in_admin_status_list' => true,
105
-				'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'pronamic_ideal' ),
105
+				'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'pronamic_ideal'),
106 106
 			)
107 107
 		);
108 108
 
109 109
 		register_post_status(
110 110
 			'subscr_expired', array(
111
-				'label'                     => _x( 'Expired', 'Subscription status', 'pronamic_ideal' ),
111
+				'label'                     => _x('Expired', 'Subscription status', 'pronamic_ideal'),
112 112
 				'public'                    => false,
113 113
 				'exclude_from_search'       => false,
114 114
 				'show_in_admin_all_list'    => true,
115 115
 				'show_in_admin_status_list' => true,
116
-				'label_count'               => _n_noop( 'Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>', 'pronamic_ideal' ),
116
+				'label_count'               => _n_noop('Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>', 'pronamic_ideal'),
117 117
 			)
118 118
 		);
119 119
 
120 120
 		register_post_status(
121 121
 			'subscr_failed', array(
122
-				'label'                     => _x( 'Failed', 'Subscription status', 'pronamic_ideal' ),
122
+				'label'                     => _x('Failed', 'Subscription status', 'pronamic_ideal'),
123 123
 				'public'                    => false,
124 124
 				'exclude_from_search'       => false,
125 125
 				'show_in_admin_all_list'    => true,
126 126
 				'show_in_admin_status_list' => true,
127
-				'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'pronamic_ideal' ),
127
+				'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'pronamic_ideal'),
128 128
 			)
129 129
 		);
130 130
 
131 131
 		register_post_status(
132 132
 			'subscr_active', array(
133
-				'label'                     => _x( 'Active', 'Subscription status', 'pronamic_ideal' ),
133
+				'label'                     => _x('Active', 'Subscription status', 'pronamic_ideal'),
134 134
 				'public'                    => false,
135 135
 				'exclude_from_search'       => false,
136 136
 				'show_in_admin_all_list'    => true,
137 137
 				'show_in_admin_status_list' => true,
138
-				'label_count'               => _n_noop( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'pronamic_ideal' ),
138
+				'label_count'               => _n_noop('Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', 'pronamic_ideal'),
139 139
 			)
140 140
 		);
141 141
 
142 142
 		register_post_status(
143 143
 			'subscr_completed', array(
144
-				'label'                     => _x( 'Completed', 'Subscription status', 'pronamic_ideal' ),
144
+				'label'                     => _x('Completed', 'Subscription status', 'pronamic_ideal'),
145 145
 				'public'                    => false,
146 146
 				'exclude_from_search'       => false,
147 147
 				'show_in_admin_all_list'    => true,
148 148
 				'show_in_admin_status_list' => true,
149
-				'label_count'               => _n_noop( 'Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'pronamic_ideal' ),
149
+				'label_count'               => _n_noop('Completed <span class="count">(%s)</span>', 'Completed <span class="count">(%s)</span>', 'pronamic_ideal'),
150 150
 			)
151 151
 		);
152 152
 	}
Please login to merge, or discard this patch.
classes/Subscriptions/SubscriptionsModule.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -44,31 +44,31 @@  discard block
 block discarded – undo
44 44
 	 *
45 45
 	 * @param Plugin $plugin The plugin.
46 46
 	 */
47
-	public function __construct( Plugin $plugin ) {
47
+	public function __construct(Plugin $plugin) {
48 48
 		$this->plugin = $plugin;
49 49
 
50 50
 		// Actions.
51
-		add_action( 'wp_loaded', array( $this, 'handle_subscription' ) );
51
+		add_action('wp_loaded', array($this, 'handle_subscription'));
52 52
 
53
-		add_action( 'plugins_loaded', array( $this, 'maybe_schedule_subscription_payments' ), 5 );
53
+		add_action('plugins_loaded', array($this, 'maybe_schedule_subscription_payments'), 5);
54 54
 
55 55
 		// Exclude payment and subscription notes.
56
-		add_filter( 'comments_clauses', array( $this, 'exclude_subscription_comment_notes' ), 10, 2 );
56
+		add_filter('comments_clauses', array($this, 'exclude_subscription_comment_notes'), 10, 2);
57 57
 
58
-		add_action( 'pronamic_pay_new_payment', array( $this, 'maybe_create_subscription' ) );
58
+		add_action('pronamic_pay_new_payment', array($this, 'maybe_create_subscription'));
59 59
 
60 60
 		// The 'pronamic_pay_update_subscription_payments' hook adds subscription payments and sends renewal notices.
61
-		add_action( 'pronamic_pay_update_subscription_payments', array( $this, 'update_subscription_payments' ) );
61
+		add_action('pronamic_pay_update_subscription_payments', array($this, 'update_subscription_payments'));
62 62
 
63 63
 		// Listen to payment status changes so we can update related subscriptions.
64
-		add_action( 'pronamic_payment_status_update', array( $this, 'payment_status_update' ) );
64
+		add_action('pronamic_payment_status_update', array($this, 'payment_status_update'));
65 65
 
66 66
 		// WordPress CLI.
67 67
 		// @see https://github.com/woocommerce/woocommerce/blob/3.3.1/includes/class-woocommerce.php#L365-L369.
68 68
 		// @see https://github.com/woocommerce/woocommerce/blob/3.3.1/includes/class-wc-cli.php.
69 69
 		// @see https://make.wordpress.org/cli/handbook/commands-cookbook/.
70
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
71
-			WP_CLI::add_command( 'pay subscriptions test', array( $this, 'cli_subscriptions_test' ) );
70
+		if (defined('WP_CLI') && WP_CLI) {
71
+			WP_CLI::add_command('pay subscriptions test', array($this, 'cli_subscriptions_test'));
72 72
 		}
73 73
 	}
74 74
 
@@ -79,33 +79,33 @@  discard block
 block discarded – undo
79 79
 	 * email notifications so users can cancel or renew their subscription.
80 80
 	 */
81 81
 	public function handle_subscription() {
82
-		if ( ! filter_has_var( INPUT_GET, 'subscription' ) ) {
82
+		if ( ! filter_has_var(INPUT_GET, 'subscription')) {
83 83
 			return;
84 84
 		}
85 85
 
86
-		if ( ! filter_has_var( INPUT_GET, 'action' ) ) {
86
+		if ( ! filter_has_var(INPUT_GET, 'action')) {
87 87
 			return;
88 88
 		}
89 89
 
90
-		if ( ! filter_has_var( INPUT_GET, 'key' ) ) {
90
+		if ( ! filter_has_var(INPUT_GET, 'key')) {
91 91
 			return;
92 92
 		}
93 93
 
94
-		$subscription_id = filter_input( INPUT_GET, 'subscription', FILTER_SANITIZE_STRING );
95
-		$subscription    = get_pronamic_subscription( $subscription_id );
94
+		$subscription_id = filter_input(INPUT_GET, 'subscription', FILTER_SANITIZE_STRING);
95
+		$subscription    = get_pronamic_subscription($subscription_id);
96 96
 
97
-		$action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
97
+		$action = filter_input(INPUT_GET, 'action', FILTER_SANITIZE_STRING);
98 98
 
99
-		$key = filter_input( INPUT_GET, 'key', FILTER_SANITIZE_STRING );
99
+		$key = filter_input(INPUT_GET, 'key', FILTER_SANITIZE_STRING);
100 100
 
101 101
 		// Check if subscription is valid.
102
-		if ( ! $subscription ) {
102
+		if ( ! $subscription) {
103 103
 			return;
104 104
 		}
105 105
 
106 106
 		// Check if subscription key is valid.
107
-		if ( $key !== $subscription->get_key() ) {
108
-			wp_redirect( home_url() );
107
+		if ($key !== $subscription->get_key()) {
108
+			wp_redirect(home_url());
109 109
 
110 110
 			exit;
111 111
 		}
@@ -113,28 +113,28 @@  discard block
 block discarded – undo
113 113
 		// Check if we should redirect.
114 114
 		$should_redirect = true;
115 115
 
116
-		switch ( $action ) {
116
+		switch ($action) {
117 117
 			case 'cancel':
118
-				if ( Statuses::CANCELLED !== $subscription->get_status() ) {
119
-					$subscription->update_status( Statuses::CANCELLED );
118
+				if (Statuses::CANCELLED !== $subscription->get_status()) {
119
+					$subscription->update_status(Statuses::CANCELLED);
120 120
 
121
-					$this->update_subscription( $subscription, $should_redirect );
121
+					$this->update_subscription($subscription, $should_redirect);
122 122
 				}
123 123
 
124 124
 				break;
125 125
 			case 'renew':
126
-				$gateway = Plugin::get_gateway( $subscription->config_id );
126
+				$gateway = Plugin::get_gateway($subscription->config_id);
127 127
 
128
-				if ( Statuses::SUCCESS !== $subscription->get_status() ) {
129
-					$payment = $this->start_recurring( $subscription, $gateway, true );
128
+				if (Statuses::SUCCESS !== $subscription->get_status()) {
129
+					$payment = $this->start_recurring($subscription, $gateway, true);
130 130
 
131
-					if ( ! $gateway->has_error() ) {
131
+					if ( ! $gateway->has_error()) {
132 132
 						// Redirect.
133
-						$gateway->redirect( $payment );
133
+						$gateway->redirect($payment);
134 134
 					}
135 135
 				}
136 136
 
137
-				wp_redirect( home_url() );
137
+				wp_redirect(home_url());
138 138
 
139 139
 				exit;
140 140
 		}
@@ -147,21 +147,21 @@  discard block
 block discarded – undo
147 147
 	 * @param Gateway      $gateway      The gateway to start the recurring payment at.
148 148
 	 * @param boolean      $renewal      Flag for renewal payment.
149 149
 	 */
150
-	public function start_recurring( Subscription $subscription, Gateway $gateway, $renewal = false ) {
151
-		if ( empty( $subscription->next_payment ) ) {
150
+	public function start_recurring(Subscription $subscription, Gateway $gateway, $renewal = false) {
151
+		if (empty($subscription->next_payment)) {
152 152
 			$subscription->status = Statuses::COMPLETED;
153 153
 
154
-			$result = $this->plugin->subscriptions_data_store->update( $subscription );
154
+			$result = $this->plugin->subscriptions_data_store->update($subscription);
155 155
 
156 156
 			// @todo
157 157
 			return;
158 158
 		}
159 159
 
160
-		if ( ! empty( $subscription->final_payment ) && $subscription->final_payment <= $subscription->next_payment ) {
160
+		if ( ! empty($subscription->final_payment) && $subscription->final_payment <= $subscription->next_payment) {
161 161
 			$subscription->next_payment = null;
162 162
 			$subscription->status       = Statuses::COMPLETED;
163 163
 
164
-			$result = $this->plugin->subscriptions_data_store->update( $subscription );
164
+			$result = $this->plugin->subscriptions_data_store->update($subscription);
165 165
 
166 166
 			// @todo
167 167
 			return;
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		$start_date = $subscription->next_payment;
171 171
 
172 172
 		$end_date = clone $start_date;
173
-		$end_date->add( $subscription->get_date_interval() );
173
+		$end_date->add($subscription->get_date_interval());
174 174
 
175 175
 		$subscription->next_payment = $end_date;
176 176
 
@@ -202,10 +202,10 @@  discard block
 block discarded – undo
202 202
 		$payment->recurring        = ! $renewal;
203 203
 
204 204
 		// Start payment.
205
-		$payment = Plugin::start_payment( $payment, $gateway );
205
+		$payment = Plugin::start_payment($payment, $gateway);
206 206
 
207 207
 		// Update subscription.
208
-		$result = $this->plugin->subscriptions_data_store->update( $subscription );
208
+		$result = $this->plugin->subscriptions_data_store->update($subscription);
209 209
 
210 210
 		return $payment;
211 211
 	}
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
 	 * @param Subscription $subscription The updated subscription.
217 217
 	 * @param boolean      $can_redirect Flag to redirect or not.
218 218
 	 */
219
-	public function update_subscription( $subscription = null, $can_redirect = true ) {
220
-		if ( empty( $subscription ) ) {
219
+	public function update_subscription($subscription = null, $can_redirect = true) {
220
+		if (empty($subscription)) {
221 221
 			return;
222 222
 		}
223 223
 
224
-		$this->plugin->subscriptions_data_store->update( $subscription );
224
+		$this->plugin->subscriptions_data_store->update($subscription);
225 225
 
226
-		if ( defined( 'DOING_CRON' ) && empty( $subscription->status ) ) {
226
+		if (defined('DOING_CRON') && empty($subscription->status)) {
227 227
 			$can_redirect = false;
228 228
 		}
229 229
 
230
-		if ( $can_redirect ) {
231
-			wp_redirect( home_url() );
230
+		if ($can_redirect) {
231
+			wp_redirect(home_url());
232 232
 
233 233
 			exit;
234 234
 		}
@@ -241,11 +241,11 @@  discard block
 block discarded – undo
241 241
 	 * @param WP_Comment_Query $query   The WordPress comment query object.
242 242
 	 * @return array
243 243
 	 */
244
-	public function exclude_subscription_comment_notes( $clauses, $query ) {
244
+	public function exclude_subscription_comment_notes($clauses, $query) {
245 245
 		$type = $query->query_vars['type'];
246 246
 
247 247
 		// Ignore subscription notes comments if it's not specifically requested.
248
-		if ( 'subscription_note' !== $type ) {
248
+		if ('subscription_note' !== $type) {
249 249
 			$clauses['where'] .= " AND comment_type != 'subscription_note'";
250 250
 		}
251 251
 
@@ -256,11 +256,11 @@  discard block
 block discarded – undo
256 256
 	 * Maybe schedule subscription payments.
257 257
 	 */
258 258
 	public function maybe_schedule_subscription_payments() {
259
-		if ( wp_next_scheduled( 'pronamic_pay_update_subscription_payments' ) ) {
259
+		if (wp_next_scheduled('pronamic_pay_update_subscription_payments')) {
260 260
 			return;
261 261
 		}
262 262
 
263
-		wp_schedule_event( time(), 'hourly', 'pronamic_pay_update_subscription_payments' );
263
+		wp_schedule_event(time(), 'hourly', 'pronamic_pay_update_subscription_payments');
264 264
 	}
265 265
 
266 266
 	/**
@@ -268,11 +268,11 @@  discard block
 block discarded – undo
268 268
 	 *
269 269
 	 * @param Payment $payment The new payment.
270 270
 	 */
271
-	public function maybe_create_subscription( $payment ) {
271
+	public function maybe_create_subscription($payment) {
272 272
 		// Check if there is already subscription attached to the payment.
273 273
 		$subscription_id = $payment->get_subscription_id();
274 274
 
275
-		if ( ! empty( $subscription_id ) ) {
275
+		if ( ! empty($subscription_id)) {
276 276
 			// Subscription already created.
277 277
 			return;
278 278
 		}
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 		// Check if there is a subscription object attached to the payment.
281 281
 		$subscription_data = $payment->subscription;
282 282
 
283
-		if ( empty( $subscription_data ) ) {
283
+		if (empty($subscription_data)) {
284 284
 			return;
285 285
 		}
286 286
 
@@ -289,13 +289,13 @@  discard block
 block discarded – undo
289 289
 
290 290
 		$subscription->config_id       = $payment->config_id;
291 291
 		$subscription->user_id         = $payment->user_id;
292
-		$subscription->title           = sprintf( __( 'Subscription for %s', 'pronamic_ideal' ), $payment->title );
292
+		$subscription->title           = sprintf(__('Subscription for %s', 'pronamic_ideal'), $payment->title);
293 293
 		$subscription->frequency       = $subscription_data->get_frequency();
294 294
 		$subscription->interval        = $subscription_data->get_interval();
295 295
 		$subscription->interval_period = $subscription_data->get_interval_period();
296 296
 		$subscription->currency        = $subscription_data->get_currency();
297 297
 		$subscription->amount          = $subscription_data->get_amount();
298
-		$subscription->key             = uniqid( 'subscr_' );
298
+		$subscription->key             = uniqid('subscr_');
299 299
 		$subscription->source          = $payment->source;
300 300
 		$subscription->source_id       = $payment->source_id;
301 301
 		$subscription->description     = $payment->description;
@@ -314,20 +314,20 @@  discard block
 block discarded – undo
314 314
 		$expiry_date = $start_date;
315 315
 
316 316
 		$next_date = clone $start_date;
317
-		$next_date->add( $interval );
317
+		$next_date->add($interval);
318 318
 
319 319
 		$notice_date = clone $next_date;
320
-		$notice_date->modify( '-1 week' );
320
+		$notice_date->modify('-1 week');
321 321
 
322 322
 		$final_date = null;
323 323
 
324
-		if ( $subscription_data->frequency ) {
324
+		if ($subscription_data->frequency) {
325 325
 			// @see https://stackoverflow.com/a/10818981/6411283
326
-			$period = new DatePeriod( $start_date, $interval, $subscription_data->frequency );
326
+			$period = new DatePeriod($start_date, $interval, $subscription_data->frequency);
327 327
 
328
-			$dates = iterator_to_array( $period );
328
+			$dates = iterator_to_array($period);
329 329
 
330
-			$final_date = end( $dates );
330
+			$final_date = end($dates);
331 331
 		}
332 332
 
333 333
 		$subscription->start_date     = $start_date;
@@ -338,16 +338,16 @@  discard block
 block discarded – undo
338 338
 		$subscription->renewal_notice = $notice_date;
339 339
 
340 340
 		// Create.
341
-		$result = $this->plugin->subscriptions_data_store->create( $subscription );
341
+		$result = $this->plugin->subscriptions_data_store->create($subscription);
342 342
 
343
-		if ( $result ) {
343
+		if ($result) {
344 344
 			$payment->subscription_id = $subscription->get_id();
345 345
 
346 346
 			$payment->recurring_type = 'first';
347 347
 			$payment->start_date     = $start_date;
348 348
 			$payment->end_date       = $next_date;
349 349
 
350
-			$this->plugin->payments_data_store->update( $payment );
350
+			$this->plugin->payments_data_store->update($payment);
351 351
 		}
352 352
 	}
353 353
 
@@ -381,24 +381,24 @@  discard block
 block discarded – undo
381 381
 				),
382 382
 				array(
383 383
 					'key'     => '_pronamic_subscription_next_payment',
384
-					'value'   => current_time( 'mysql', true ),
384
+					'value'   => current_time('mysql', true),
385 385
 					'compare' => '<=',
386 386
 					'type'    => 'DATETIME',
387 387
 				),
388 388
 			),
389 389
 		);
390 390
 
391
-		$query = new WP_Query( $args );
391
+		$query = new WP_Query($args);
392 392
 
393
-		foreach ( $query->posts as $post ) {
394
-			$subscription = new Subscription( $post->ID );
393
+		foreach ($query->posts as $post) {
394
+			$subscription = new Subscription($post->ID);
395 395
 
396
-			$gateway = Plugin::get_gateway( $subscription->config_id );
396
+			$gateway = Plugin::get_gateway($subscription->config_id);
397 397
 
398
-			$payment = $this->start_recurring( $subscription, $gateway );
398
+			$payment = $this->start_recurring($subscription, $gateway);
399 399
 
400
-			if ( $payment ) {
401
-				Plugin::update_payment( $payment, false );
400
+			if ($payment) {
401
+				Plugin::update_payment($payment, false);
402 402
 			}
403 403
 		}
404 404
 	}
@@ -421,36 +421,36 @@  discard block
 block discarded – undo
421 421
 			'meta_query'  => array(
422 422
 				array(
423 423
 					'key'     => '_pronamic_subscription_renewal_notice',
424
-					'value'   => current_time( 'mysql', true ),
424
+					'value'   => current_time('mysql', true),
425 425
 					'compare' => '<=',
426 426
 					'type'    => 'DATETIME',
427 427
 				),
428 428
 			),
429 429
 		);
430 430
 
431
-		$query = new WP_Query( $args );
431
+		$query = new WP_Query($args);
432 432
 
433
-		foreach ( $query->posts as $post ) {
434
-			$subscription = new Subscription( $post->ID );
433
+		foreach ($query->posts as $post) {
434
+			$subscription = new Subscription($post->ID);
435 435
 
436
-			do_action( 'pronamic_subscription_renewal_notice_' . $subscription->get_source(), $subscription );
436
+			do_action('pronamic_subscription_renewal_notice_' . $subscription->get_source(), $subscription);
437 437
 
438 438
 			// Set next renewal date meta.
439
-			$next_renewal = $subscription->get_next_payment_date( 1 );
439
+			$next_renewal = $subscription->get_next_payment_date(1);
440 440
 
441
-			if ( $next_renewal ) {
442
-				$next_renewal->modify( '-1 week' );
441
+			if ($next_renewal) {
442
+				$next_renewal->modify('-1 week');
443 443
 
444 444
 				// If next renewal notice date is before next payment date,
445 445
 				// prevent duplicate renewal messages by setting the renewal
446 446
 				// notice date to the date of next payment.
447
-				if ( $next_renewal < $subscription->get_next_payment_date() ) {
447
+				if ($next_renewal < $subscription->get_next_payment_date()) {
448 448
 					$next_renewal = $subscription->get_next_payment_date();
449 449
 				}
450 450
 			}
451 451
 
452 452
 			// Update or delete next renewal notice date meta.
453
-			$subscription->set_renewal_notice_date( $next_renewal );
453
+			$subscription->set_renewal_notice_date($next_renewal);
454 454
 		}
455 455
 	}
456 456
 
@@ -459,61 +459,61 @@  discard block
 block discarded – undo
459 459
 	 *
460 460
 	 * @param Payment $payment The status updated payment.
461 461
 	 */
462
-	public function payment_status_update( $payment ) {
462
+	public function payment_status_update($payment) {
463 463
 		// Check if the payment is connected to a subscription.
464 464
 		$subscription = $payment->get_subscription();
465 465
 
466
-		if ( empty( $subscription ) ) {
466
+		if (empty($subscription)) {
467 467
 			// Payment not connected to a subscription, nothing to do.
468 468
 			return;
469 469
 		}
470 470
 
471
-		if ( empty( $payment->start_date ) ) {
471
+		if (empty($payment->start_date)) {
472 472
 			return;
473 473
 		}
474 474
 
475
-		if ( empty( $payment->end_date ) ) {
475
+		if (empty($payment->end_date)) {
476 476
 			return;
477 477
 		}
478 478
 
479
-		if ( Statuses::CANCELLED === $subscription->get_status() ) {
479
+		if (Statuses::CANCELLED === $subscription->get_status()) {
480 480
 			// If subscritpion is cancelled never change the subscription status.
481 481
 			return;
482 482
 		}
483 483
 
484 484
 		// Status.
485
-		switch ( $payment->get_status() ) {
485
+		switch ($payment->get_status()) {
486 486
 			case Statuses::OPEN:
487 487
 				// @todo
488 488
 				break;
489 489
 			case Statuses::SUCCESS:
490
-				$subscription->set_status( Statuses::SUCCESS );
490
+				$subscription->set_status(Statuses::SUCCESS);
491 491
 
492
-				if ( $subscription->expiry_date < $payment->end_date ) {
492
+				if ($subscription->expiry_date < $payment->end_date) {
493 493
 					$subscription->expiry_date = $payment->end_date;
494 494
 				}
495 495
 
496 496
 				break;
497 497
 			case Statuses::FAILURE:
498
-				$subscription->set_status( Statuses::CANCELLED );
498
+				$subscription->set_status(Statuses::CANCELLED);
499 499
 
500 500
 				break;
501 501
 			case Statuses::CANCELLED:
502
-				$subscription->set_status( Statuses::CANCELLED );
502
+				$subscription->set_status(Statuses::CANCELLED);
503 503
 
504 504
 				break;
505 505
 			case Statuses::EXPIRED:
506
-				$subscription->set_status( Statuses::CANCELLED );
506
+				$subscription->set_status(Statuses::CANCELLED);
507 507
 
508 508
 				break;
509 509
 			case Statuses::COMPLETED:
510
-				$subscription->set_status( Statuses::COMPLETED );
510
+				$subscription->set_status(Statuses::COMPLETED);
511 511
 
512 512
 				break;
513 513
 		}
514 514
 
515 515
 		// Update.
516
-		$result = $this->plugin->subscriptions_data_store->update( $subscription );
516
+		$result = $this->plugin->subscriptions_data_store->update($subscription);
517 517
 	}
518 518
 
519 519
 	/**
@@ -543,22 +543,22 @@  discard block
 block discarded – undo
543 543
 			),
544 544
 		);
545 545
 
546
-		$query = new WP_Query( $args );
546
+		$query = new WP_Query($args);
547 547
 
548
-		foreach ( $query->posts as $post ) {
549
-			WP_CLI::log( sprintf( 'Processing post `%d` - "%s"…', $post->ID, get_the_title( $post ) ) );
548
+		foreach ($query->posts as $post) {
549
+			WP_CLI::log(sprintf('Processing post `%d` - "%s"…', $post->ID, get_the_title($post)));
550 550
 
551
-			$subscription = new Subscription( $post->ID );
551
+			$subscription = new Subscription($post->ID);
552 552
 
553
-			$gateway = Plugin::get_gateway( $subscription->config_id );
553
+			$gateway = Plugin::get_gateway($subscription->config_id);
554 554
 
555
-			$payment = $this->start_recurring( $subscription, $gateway );
555
+			$payment = $this->start_recurring($subscription, $gateway);
556 556
 
557
-			if ( $payment ) {
558
-				Plugin::update_payment( $payment, false );
557
+			if ($payment) {
558
+				Plugin::update_payment($payment, false);
559 559
 			}
560 560
 		}
561 561
 
562
-		WP_CLI::success( 'Pronamic Pay subscriptions test.' );
562
+		WP_CLI::success('Pronamic Pay subscriptions test.');
563 563
 	}
564 564
 }
Please login to merge, or discard this patch.
classes/Subscriptions/Subscription.php 1 patch
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -284,15 +284,15 @@  discard block
 block discarded – undo
284 284
 	 *
285 285
 	 * @param int $post_id A subscription post ID or null.
286 286
 	 */
287
-	public function __construct( $post_id = null ) {
287
+	public function __construct($post_id = null) {
288 288
 		$this->id   = $post_id;
289 289
 		$this->date = new \DateTime();
290 290
 		$this->meta = array();
291 291
 
292
-		if ( null !== $post_id ) {
292
+		if (null !== $post_id) {
293 293
 			global $pronamic_ideal;
294 294
 
295
-			$pronamic_ideal->subscriptions_data_store->read( $this );
295
+			$pronamic_ideal->subscriptions_data_store->read($this);
296 296
 		}
297 297
 	}
298 298
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
 	 *
311 311
 	 * @param string $id The ID of this subscription.
312 312
 	 */
313
-	public function set_id( $id ) {
313
+	public function set_id($id) {
314 314
 		$this->id = $id;
315 315
 	}
316 316
 
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 	public function get_date_interval() {
383 383
 		$interval_spec = 'P' . $this->interval . $this->interval_period;
384 384
 
385
-		$interval = new DateInterval( $interval_spec );
385
+		$interval = new DateInterval($interval_spec);
386 386
 
387 387
 		return $interval;
388 388
 	}
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 *
429 429
 	 * @param string $transaction_id A transaction ID.
430 430
 	 */
431
-	public function set_transaction_id( $transaction_id ) {
431
+	public function set_transaction_id($transaction_id) {
432 432
 		$this->transaction_id = $transaction_id;
433 433
 	}
434 434
 
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 	 * @todo  Check constant?
449 449
 	 * @param string $status A status string.
450 450
 	 */
451
-	public function set_status( $status ) {
451
+	public function set_status($status) {
452 452
 		$this->status = $status;
453 453
 	}
454 454
 
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
 	 *
458 458
 	 * @param string $name A name.
459 459
 	 */
460
-	public function set_consumer_name( $name ) {
460
+	public function set_consumer_name($name) {
461 461
 		$this->consumer_name = $name;
462 462
 	}
463 463
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
 	 *
467 467
 	 * @param string $iban A IBAN.
468 468
 	 */
469
-	public function set_consumer_iban( $iban ) {
469
+	public function set_consumer_iban($iban) {
470 470
 		$this->consumer_iban = $iban;
471 471
 	}
472 472
 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 	 *
476 476
 	 * @param string $bic A BIC.
477 477
 	 */
478
-	public function set_consumer_bic( $bic ) {
478
+	public function set_consumer_bic($bic) {
479 479
 		$this->consumer_bic = $bic;
480 480
 	}
481 481
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @param string $note A Note.
486 486
 	 */
487
-	public function add_note( $note ) {
487
+	public function add_note($note) {
488 488
 		$commentdata = array(
489 489
 			'comment_post_ID'      => $this->id,
490 490
 			'comment_author'       => 'admin',
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 			'comment_approved'     => 1,
498 498
 		);
499 499
 
500
-		$comment_id = wp_insert_comment( $commentdata );
500
+		$comment_id = wp_insert_comment($commentdata);
501 501
 
502 502
 		return $comment_id;
503 503
 	}
@@ -508,10 +508,10 @@  discard block
 block discarded – undo
508 508
 	 * @param string $key A meta key.
509 509
 	 * @return string
510 510
 	 */
511
-	public function get_meta( $key ) {
511
+	public function get_meta($key) {
512 512
 		$key = '_pronamic_subscription_' . $key;
513 513
 
514
-		return get_post_meta( $this->id, $key, true );
514
+		return get_post_meta($this->id, $key, true);
515 515
 	}
516 516
 
517 517
 	/**
@@ -522,18 +522,18 @@  discard block
 block discarded – undo
522 522
 	 *
523 523
 	 * @return boolean        True on successful update, false on failure.
524 524
 	 */
525
-	public function set_meta( $key, $value = false ) {
525
+	public function set_meta($key, $value = false) {
526 526
 		$key = '_pronamic_subscription_' . $key;
527 527
 
528
-		if ( $value instanceof DateTime ) {
529
-			$value = $value->format( 'Y-m-d H:i:s' );
528
+		if ($value instanceof DateTime) {
529
+			$value = $value->format('Y-m-d H:i:s');
530 530
 		}
531 531
 
532
-		if ( empty( $value ) ) {
533
-			return delete_post_meta( $this->id, $key );
532
+		if (empty($value)) {
533
+			return delete_post_meta($this->id, $key);
534 534
 		}
535 535
 
536
-		return update_post_meta( $this->id, $key, $value );
536
+		return update_post_meta($this->id, $key, $value);
537 537
 	}
538 538
 
539 539
 	/**
@@ -546,9 +546,9 @@  discard block
 block discarded – undo
546 546
 
547 547
 		$payment = $this->get_first_payment();
548 548
 
549
-		if ( $payment ) {
550
-			$description = apply_filters( 'pronamic_payment_source_description', $description, $payment );
551
-			$description = apply_filters( 'pronamic_payment_source_description_' . $this->source, $description, $payment );
549
+		if ($payment) {
550
+			$description = apply_filters('pronamic_payment_source_description', $description, $payment);
551
+			$description = apply_filters('pronamic_payment_source_description_' . $this->source, $description, $payment);
552 552
 		}
553 553
 
554 554
 		return $description;
@@ -564,9 +564,9 @@  discard block
 block discarded – undo
564 564
 
565 565
 		$payment = $this->get_first_payment();
566 566
 
567
-		if ( $payment ) {
568
-			$url = apply_filters( 'pronamic_payment_source_url', $url, $payment );
569
-			$url = apply_filters( 'pronamic_payment_source_url_' . $this->source, $url, $payment );
567
+		if ($payment) {
568
+			$url = apply_filters('pronamic_payment_source_url', $url, $payment);
569
+			$url = apply_filters('pronamic_payment_source_url_' . $this->source, $url, $payment);
570 570
 		}
571 571
 
572 572
 		return $url;
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 	 * @return array
613 613
 	 */
614 614
 	public function get_payments() {
615
-		return get_pronamic_payments_by_meta( '_pronamic_payment_subscription_id', $this->id );
615
+		return get_pronamic_payments_by_meta('_pronamic_payment_subscription_id', $this->id);
616 616
 	}
617 617
 
618 618
 	/**
@@ -623,8 +623,8 @@  discard block
 block discarded – undo
623 623
 	public function has_valid_payment() {
624 624
 		$payments = $this->get_payments();
625 625
 
626
-		foreach ( $payments as $payment ) {
627
-			if ( Statuses::SUCCESS === $payment->get_status() ) {
626
+		foreach ($payments as $payment) {
627
+			if (Statuses::SUCCESS === $payment->get_status()) {
628 628
 				return $payment;
629 629
 			}
630 630
 		}
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 	public function get_first_payment() {
641 641
 		$payments = $this->get_payments();
642 642
 
643
-		if ( count( $payments ) > 0 ) {
643
+		if (count($payments) > 0) {
644 644
 			return $payments[0];
645 645
 		}
646 646
 
@@ -653,8 +653,8 @@  discard block
 block discarded – undo
653 653
 	 * @todo  Should we set meta directly?
654 654
 	 * @param string $value A date value.
655 655
 	 */
656
-	public function set_start_date( $value ) {
657
-		$this->set_meta( 'start_date', $value );
656
+	public function set_start_date($value) {
657
+		$this->set_meta('start_date', $value);
658 658
 	}
659 659
 
660 660
 	/**
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 	 * @return \DateTimeInterface
665 665
 	 */
666 666
 	public function get_start_date() {
667
-		$start_date = $this->get_meta( 'start_date' );
667
+		$start_date = $this->get_meta('start_date');
668 668
 
669
-		if ( '' !== $start_date ) {
670
-			return new DateTime( $start_date );
669
+		if ('' !== $start_date) {
670
+			return new DateTime($start_date);
671 671
 		}
672 672
 
673
-		if ( Statuses::COMPLETED !== $this->get_status() ) {
674
-			return new DateTime( $this->post->post_date_gmt );
673
+		if (Statuses::COMPLETED !== $this->get_status()) {
674
+			return new DateTime($this->post->post_date_gmt);
675 675
 		}
676 676
 
677 677
 		return null;
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
 	 * @todo  Should we set meta directly?
684 684
 	 * @param string $value A date value.
685 685
 	 */
686
-	public function set_expiry_date( $value ) {
687
-		$this->set_meta( 'expiry_date', $value );
686
+	public function set_expiry_date($value) {
687
+		$this->set_meta('expiry_date', $value);
688 688
 	}
689 689
 
690 690
 	/**
@@ -694,16 +694,16 @@  discard block
 block discarded – undo
694 694
 	 * @return \DateTimeInterface
695 695
 	 */
696 696
 	public function get_expiry_date() {
697
-		$expiry_date = $this->get_meta( 'expiry_date' );
697
+		$expiry_date = $this->get_meta('expiry_date');
698 698
 
699
-		if ( '' !== $expiry_date ) {
700
-			return new DateTime( $expiry_date );
699
+		if ('' !== $expiry_date) {
700
+			return new DateTime($expiry_date);
701 701
 		}
702 702
 
703 703
 		// If no meta expiry date is set, use start date + 1 interval period.
704 704
 		$start_date = $this->get_start_date();
705 705
 
706
-		if ( null === $start_date ) {
706
+		if (null === $start_date) {
707 707
 			return null;
708 708
 		}
709 709
 
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 			sprintf(
712 712
 				'+%d %s',
713 713
 				$this->get_interval(),
714
-				Util::to_interval_name( $this->get_interval_period() )
714
+				Util::to_interval_name($this->get_interval_period())
715 715
 			)
716 716
 		);
717 717
 	}
@@ -722,8 +722,8 @@  discard block
 block discarded – undo
722 722
 	 * @todo  Should we set meta directly?
723 723
 	 * @param string $value A date value.
724 724
 	 */
725
-	public function set_first_payment_date( $value ) {
726
-		$this->set_meta( 'first_payment', $value );
725
+	public function set_first_payment_date($value) {
726
+		$this->set_meta('first_payment', $value);
727 727
 	}
728 728
 
729 729
 	/**
@@ -733,13 +733,13 @@  discard block
 block discarded – undo
733 733
 	 * @return \DateTimeInterface
734 734
 	 */
735 735
 	public function get_first_payment_date() {
736
-		$first_date = $this->get_meta( 'first_payment' );
736
+		$first_date = $this->get_meta('first_payment');
737 737
 
738
-		if ( '' !== $first_date ) {
739
-			return new DateTime( $first_date );
738
+		if ('' !== $first_date) {
739
+			return new DateTime($first_date);
740 740
 		}
741 741
 
742
-		return new DateTime( $this->post->post_date_gmt );
742
+		return new DateTime($this->post->post_date_gmt);
743 743
 	}
744 744
 
745 745
 	/**
@@ -748,8 +748,8 @@  discard block
 block discarded – undo
748 748
 	 * @todo  Should we set meta directly?
749 749
 	 * @param string $value A date value.
750 750
 	 */
751
-	public function set_final_payment_date( $value ) {
752
-		$this->set_meta( 'final_payment', $value );
751
+	public function set_final_payment_date($value) {
752
+		$this->set_meta('final_payment', $value);
753 753
 	}
754 754
 
755 755
 	/**
@@ -759,19 +759,19 @@  discard block
 block discarded – undo
759 759
 	 * @return \DateTimeInterface
760 760
 	 */
761 761
 	public function get_final_payment_date() {
762
-		$final = $this->get_meta( 'final_payment' );
762
+		$final = $this->get_meta('final_payment');
763 763
 
764
-		if ( '' !== $final ) {
765
-			return new DateTime( $final );
764
+		if ('' !== $final) {
765
+			return new DateTime($final);
766 766
 		}
767 767
 
768 768
 		// If no frequency is set, use next payment or start date.
769 769
 		$frequency = $this->get_frequency();
770 770
 
771
-		if ( '' === $frequency ) {
771
+		if ('' === $frequency) {
772 772
 			$next_date = $this->get_next_payment_date();
773 773
 
774
-			if ( null === $next_date ) {
774
+			if (null === $next_date) {
775 775
 				return $this->get_start_date();
776 776
 			}
777 777
 
@@ -784,8 +784,8 @@  discard block
 block discarded – undo
784 784
 		return $first_date->modify(
785 785
 			sprintf(
786 786
 				'+%d %s',
787
-				( $frequency - 1 ) * $this->get_interval(),
788
-				Util::to_interval_name( $this->get_interval_period() )
787
+				($frequency - 1) * $this->get_interval(),
788
+				Util::to_interval_name($this->get_interval_period())
789 789
 			)
790 790
 		);
791 791
 	}
@@ -796,11 +796,11 @@  discard block
 block discarded – undo
796 796
 	 * @todo  Should we set meta directly?
797 797
 	 * @param string $value A date value.
798 798
 	 */
799
-	public function set_next_payment_date( $value ) {
800
-		$this->set_meta( 'next_payment', $value );
799
+	public function set_next_payment_date($value) {
800
+		$this->set_meta('next_payment', $value);
801 801
 
802
-		if ( false === $value ) {
803
-			$this->set_renewal_notice_date( false );
802
+		if (false === $value) {
803
+			$this->set_renewal_notice_date(false);
804 804
 		}
805 805
 	}
806 806
 
@@ -811,22 +811,22 @@  discard block
 block discarded – undo
811 811
 	 * @param  int $cycle TODO.
812 812
 	 * @return \DateTimeInterface
813 813
 	 */
814
-	public function get_next_payment_date( $cycle = 0 ) {
814
+	public function get_next_payment_date($cycle = 0) {
815 815
 		// Meta next_payment, possibly doesn't exist if last payment has been processed.
816
-		$next_payment = $this->get_meta( 'next_payment' );
816
+		$next_payment = $this->get_meta('next_payment');
817 817
 
818
-		if ( '' === $next_payment ) {
818
+		if ('' === $next_payment) {
819 819
 			return;
820 820
 		}
821 821
 
822
-		$next = new DateTime( $next_payment );
822
+		$next = new DateTime($next_payment);
823 823
 
824
-		if ( 0 !== $cycle ) {
824
+		if (0 !== $cycle) {
825 825
 			$next->modify(
826 826
 				sprintf(
827 827
 					'+%d %s',
828
-					( $cycle * $this->get_interval() ),
829
-					Util::to_interval_name( $this->get_interval_period() )
828
+					($cycle * $this->get_interval()),
829
+					Util::to_interval_name($this->get_interval_period())
830 830
 				)
831 831
 			);
832 832
 		}
@@ -840,28 +840,28 @@  discard block
 block discarded – undo
840 840
 	 * @todo Should we handle logic like this in a private function?
841 841
 	 */
842 842
 	private function refresh_next_payment_date() {
843
-		if ( null !== $this->get_next_payment_date() ) {
843
+		if (null !== $this->get_next_payment_date()) {
844 844
 			// Only set next payment date if not set already.
845 845
 			return;
846 846
 		}
847 847
 
848 848
 		$expiry = $this->get_expiry_date();
849
-		$now    = new DateTime( 'now', new DateTimeZone( Plugin::TIMEZONE ) );
849
+		$now    = new DateTime('now', new DateTimeZone(Plugin::TIMEZONE));
850 850
 
851
-		if ( $expiry > $now ) {
851
+		if ($expiry > $now) {
852 852
 			// Expiry date is in the future, use it.
853 853
 			$next_payment = $expiry;
854 854
 		} else {
855 855
 			$next_payment = $now;
856 856
 		}
857 857
 
858
-		$this->set_next_payment_date( $next_payment );
858
+		$this->set_next_payment_date($next_payment);
859 859
 
860 860
 		// Update renewal notice date.
861
-		$next_renewal = new DateTime( $next_payment->format( DateTime::ISO8601 ) );
862
-		$next_renewal->modify( '-1 week' );
861
+		$next_renewal = new DateTime($next_payment->format(DateTime::ISO8601));
862
+		$next_renewal->modify('-1 week');
863 863
 
864
-		$this->set_renewal_notice_date( $next_renewal );
864
+		$this->set_renewal_notice_date($next_renewal);
865 865
 	}
866 866
 
867 867
 	/**
@@ -870,8 +870,8 @@  discard block
 block discarded – undo
870 870
 	 * @todo  Should we set meta directly?
871 871
 	 * @param string $value A date value.
872 872
 	 */
873
-	public function set_renewal_notice_date( $value ) {
874
-		$this->set_meta( 'renewal_notice', $value );
873
+	public function set_renewal_notice_date($value) {
874
+		$this->set_meta('renewal_notice', $value);
875 875
 	}
876 876
 
877 877
 	/**
@@ -881,9 +881,9 @@  discard block
 block discarded – undo
881 881
 	 * @return \DateTimeInterface
882 882
 	 */
883 883
 	public function get_renewal_notice_date() {
884
-		$renewal_notice = $this->get_meta( 'renewal_notice' );
884
+		$renewal_notice = $this->get_meta('renewal_notice');
885 885
 
886
-		if ( '' !== $renewal_notice ) {
886
+		if ('' !== $renewal_notice) {
887 887
 			return $renewal_notice;
888 888
 		}
889 889
 
@@ -897,65 +897,65 @@  discard block
 block discarded – undo
897 897
 	 * @param string $status The new status for this subscription.
898 898
 	 * @param string $note   The note to store with this status update.
899 899
 	 */
900
-	public function update_status( $status, $note = null ) {
901
-		if ( Statuses::ACTIVE === $status ) {
900
+	public function update_status($status, $note = null) {
901
+		if (Statuses::ACTIVE === $status) {
902 902
 			$status = Statuses::SUCCESS;
903 903
 		}
904 904
 
905
-		$this->set_status( $status );
905
+		$this->set_status($status);
906 906
 
907
-		switch ( $status ) {
907
+		switch ($status) {
908 908
 			case Statuses::OPEN:
909
-				$meta_status = $this->get_meta( 'status' );
909
+				$meta_status = $this->get_meta('status');
910 910
 
911
-				if ( Statuses::OPEN !== $meta_status ) {
911
+				if (Statuses::OPEN !== $meta_status) {
912 912
 					$this->refresh_next_payment_date();
913 913
 
914
-					if ( ! $note ) {
915
-						$this->add_note( __( "Subscription status changed to 'Open'", 'pronamic_ideal' ) );
914
+					if ( ! $note) {
915
+						$this->add_note(__("Subscription status changed to 'Open'", 'pronamic_ideal'));
916 916
 					}
917 917
 				}
918 918
 
919 919
 				break;
920 920
 			case Statuses::SUCCESS:
921
-				$meta_status = $this->get_meta( 'status' );
921
+				$meta_status = $this->get_meta('status');
922 922
 
923
-				if ( Statuses::SUCCESS !== $meta_status ) {
923
+				if (Statuses::SUCCESS !== $meta_status) {
924 924
 					$this->refresh_next_payment_date();
925 925
 
926
-					if ( ! $note ) {
927
-						$this->add_note( __( "Subscription status changed to 'Active'", 'pronamic_ideal' ) );
926
+					if ( ! $note) {
927
+						$this->add_note(__("Subscription status changed to 'Active'", 'pronamic_ideal'));
928 928
 					}
929 929
 				}
930 930
 
931 931
 				break;
932 932
 			case Statuses::FAILURE:
933
-				if ( ! $note ) {
934
-					$this->add_note( __( "Subscription status changed to 'Failed'", 'pronamic_ideal' ) );
933
+				if ( ! $note) {
934
+					$this->add_note(__("Subscription status changed to 'Failed'", 'pronamic_ideal'));
935 935
 				}
936 936
 
937 937
 				break;
938 938
 			case Statuses::CANCELLED:
939
-				$this->set_next_payment_date( false );
939
+				$this->set_next_payment_date(false);
940 940
 
941
-				if ( ! $note ) {
942
-					$this->add_note( __( "Subscription status changed to 'Cancelled'", 'pronamic_ideal' ) );
941
+				if ( ! $note) {
942
+					$this->add_note(__("Subscription status changed to 'Cancelled'", 'pronamic_ideal'));
943 943
 				}
944 944
 
945 945
 				break;
946 946
 			case Statuses::COMPLETED:
947
-				$this->set_next_payment_date( false );
948
-				$this->set_start_date( false );
947
+				$this->set_next_payment_date(false);
948
+				$this->set_start_date(false);
949 949
 
950
-				if ( ! $note ) {
951
-					$this->add_note( __( "Subscription status changed to 'Completed'", 'pronamic_ideal' ) );
950
+				if ( ! $note) {
951
+					$this->add_note(__("Subscription status changed to 'Completed'", 'pronamic_ideal'));
952 952
 				}
953 953
 
954 954
 				break;
955 955
 		}
956 956
 
957
-		if ( $note ) {
958
-			$this->add_note( $note );
957
+		if ($note) {
958
+			$this->add_note($note);
959 959
 		}
960 960
 
961 961
 		// Note: make sure Plugin::update_subscription( $subscription, $can_redirect ) is called after the status has been updated!
@@ -967,31 +967,31 @@  discard block
 block discarded – undo
967 967
 	 * @todo  Not sure how and when this function is used.
968 968
 	 * @param array $meta The meta data to update.
969 969
 	 */
970
-	public function update_meta( $meta ) {
971
-		if ( ! is_array( $meta ) || count( $meta ) === 0 ) {
970
+	public function update_meta($meta) {
971
+		if ( ! is_array($meta) || count($meta) === 0) {
972 972
 			return;
973 973
 		}
974 974
 
975 975
 		$note = sprintf(
976 976
 			'<p>%s:</p>',
977
-			__( 'Subscription changed', 'pronamic_ideal' )
977
+			__('Subscription changed', 'pronamic_ideal')
978 978
 		);
979 979
 
980 980
 		$note .= '<dl>';
981 981
 
982
-		foreach ( $meta as $key => $value ) {
983
-			$this->set_meta( $key, $value );
982
+		foreach ($meta as $key => $value) {
983
+			$this->set_meta($key, $value);
984 984
 
985
-			if ( $value instanceof DateTime ) {
986
-				$value = date_i18n( __( 'l jS \o\f F Y, h:ia', 'pronamic_ideal' ), $value->getTimestamp() );
985
+			if ($value instanceof DateTime) {
986
+				$value = date_i18n(__('l jS \o\f F Y, h:ia', 'pronamic_ideal'), $value->getTimestamp());
987 987
 			}
988 988
 
989
-			$note .= sprintf( '<dt>%s</dt>', esc_html( $key ) );
990
-			$note .= sprintf( '<dd>%s</dd>', esc_html( $value ) );
989
+			$note .= sprintf('<dt>%s</dt>', esc_html($key));
990
+			$note .= sprintf('<dd>%s</dd>', esc_html($value));
991 991
 		}
992 992
 
993 993
 		$note .= '</dl>';
994 994
 
995
-		$this->add_note( $note );
995
+		$this->add_note($note);
996 996
 	}
997 997
 }
Please login to merge, or discard this patch.
classes/Subscriptions/SubscriptionsDataStoreCPT.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -29,30 +29,30 @@  discard block
 block discarded – undo
29 29
 	 * @see https://github.com/woocommerce/woocommerce/blob/3.2.6/includes/data-stores/abstract-wc-order-data-store-cpt.php#L47-L76
30 30
 	 * @param Subscription $subscription Create the specified subscription in this data store.
31 31
 	 */
32
-	public function create( $subscription ) {
32
+	public function create($subscription) {
33 33
 		$result = wp_insert_post(
34 34
 			array(
35 35
 				'post_type'     => 'pronamic_pay_subscr',
36
-				'post_date_gmt' => $subscription->date->format( 'Y-m-d H:i:s' ),
36
+				'post_date_gmt' => $subscription->date->format('Y-m-d H:i:s'),
37 37
 				'post_title'    => sprintf(
38 38
 					'Subscription – %s',
39
-					date_i18n( _x( '@todo', 'Subscription title date format parsed by `date_i18n`.', 'pronamic_ideal' ) )
39
+					date_i18n(_x('@todo', 'Subscription title date format parsed by `date_i18n`.', 'pronamic_ideal'))
40 40
 				),
41
-				'post_status'   => $this->get_post_status( $subscription ),
41
+				'post_status'   => $this->get_post_status($subscription),
42 42
 				'post_author'   => $subscription->user_id,
43 43
 			), true
44 44
 		);
45 45
 
46
-		if ( is_wp_error( $result ) ) {
46
+		if (is_wp_error($result)) {
47 47
 			return false;
48 48
 		}
49 49
 
50
-		$subscription->set_id( $result );
51
-		$subscription->post = get_post( $result );
50
+		$subscription->set_id($result);
51
+		$subscription->post = get_post($result);
52 52
 
53
-		$this->update_post_meta( $subscription );
53
+		$this->update_post_meta($subscription);
54 54
 
55
-		do_action( 'pronamic_pay_new_subscription', $subscription );
55
+		do_action('pronamic_pay_new_subscription', $subscription);
56 56
 
57 57
 		return true;
58 58
 	}
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
 	 * @see https://github.com/woocommerce/woocommerce/blob/3.2.6/includes/data-stores/class-wc-order-data-store-cpt.php#L81-L136
65 65
 	 * @param Subscription $subscription The subscription to read the additional data for.
66 66
 	 */
67
-	public function read( $subscription ) {
68
-		$subscription->post    = get_post( $subscription->get_id() );
69
-		$subscription->title   = get_the_title( $subscription->get_id() );
70
-		$subscription->date    = new \DateTime( get_post_field( 'post_date_gmt', $subscription->get_id(), 'raw' ) );
71
-		$subscription->user_id = get_post_field( 'post_author', $subscription->get_id(), 'raw' );
67
+	public function read($subscription) {
68
+		$subscription->post    = get_post($subscription->get_id());
69
+		$subscription->title   = get_the_title($subscription->get_id());
70
+		$subscription->date    = new \DateTime(get_post_field('post_date_gmt', $subscription->get_id(), 'raw'));
71
+		$subscription->user_id = get_post_field('post_author', $subscription->get_id(), 'raw');
72 72
 
73
-		$this->read_post_meta( $subscription );
73
+		$this->read_post_meta($subscription);
74 74
 	}
75 75
 
76 76
 	/**
@@ -80,20 +80,20 @@  discard block
 block discarded – undo
80 80
 	 * @see https://github.com/woocommerce/woocommerce/blob/3.2.6/includes/data-stores/class-wc-order-data-store-cpt.php#L154-L257
81 81
 	 * @param Subscription $subscription The subscription to update in this data store.
82 82
 	 */
83
-	public function update( $subscription ) {
83
+	public function update($subscription) {
84 84
 		$data = array(
85 85
 			'ID' => $subscription->get_id(),
86 86
 		);
87 87
 
88
-		$post_status = $this->get_post_status( $subscription, null );
88
+		$post_status = $this->get_post_status($subscription, null);
89 89
 
90
-		if ( null !== $post_status ) {
90
+		if (null !== $post_status) {
91 91
 			$data['post_status'] = $post_status;
92 92
 		}
93 93
 
94
-		wp_update_post( $data );
94
+		wp_update_post($data);
95 95
 
96
-		$this->update_post_meta( $subscription );
96
+		$this->update_post_meta($subscription);
97 97
 	}
98 98
 
99 99
 	/**
@@ -103,8 +103,8 @@  discard block
 block discarded – undo
103 103
 	 * @param string       $default      The deafult post status if the meta status could not be converted to a post status.
104 104
 	 * @return string
105 105
 	 */
106
-	private function get_post_status( $subscription, $default = 'subscr_pending' ) {
107
-		switch ( $subscription->status ) {
106
+	private function get_post_status($subscription, $default = 'subscr_pending') {
107
+		switch ($subscription->status) {
108 108
 			case Statuses::CANCELLED:
109 109
 				return 'subscr_cancelled';
110 110
 
@@ -134,60 +134,60 @@  discard block
 block discarded – undo
134 134
 	 * @see https://github.com/woocommerce/woocommerce/blob/3.2.6/includes/abstracts/abstract-wc-data.php#L462-L507
135 135
 	 * @param Subscription $subscription The subscription to read the post meta for.
136 136
 	 */
137
-	private function read_post_meta( $subscription ) {
137
+	private function read_post_meta($subscription) {
138 138
 		$prefix = '_pronamic_subscription_';
139 139
 
140 140
 		$id = $subscription->get_id();
141 141
 
142
-		$subscription->config_id       = get_post_meta( $id, $prefix . 'config_id', true );
143
-		$subscription->key             = get_post_meta( $id, $prefix . 'key', true );
144
-		$subscription->source          = get_post_meta( $id, $prefix . 'source', true );
145
-		$subscription->source_id       = get_post_meta( $id, $prefix . 'source_id', true );
146
-		$subscription->frequency       = get_post_meta( $id, $prefix . 'frequency', true );
147
-		$subscription->interval        = get_post_meta( $id, $prefix . 'interval', true );
148
-		$subscription->interval_period = get_post_meta( $id, $prefix . 'interval_period', true );
149
-		$subscription->currency        = get_post_meta( $id, $prefix . 'currency', true );
150
-		$subscription->amount          = get_post_meta( $id, $prefix . 'amount', true );
151
-		$subscription->transaction_id  = get_post_meta( $id, $prefix . 'transaction_id', true );
152
-		$subscription->status          = get_post_meta( $id, $prefix . 'status', true );
153
-		$subscription->description     = get_post_meta( $id, $prefix . 'description', true );
154
-		$subscription->email           = get_post_meta( $id, $prefix . 'email', true );
155
-		$subscription->customer_name   = get_post_meta( $id, $prefix . 'customer_name', true );
156
-		$subscription->payment_method  = get_post_meta( $id, $prefix . 'payment_method', true );
142
+		$subscription->config_id       = get_post_meta($id, $prefix . 'config_id', true);
143
+		$subscription->key             = get_post_meta($id, $prefix . 'key', true);
144
+		$subscription->source          = get_post_meta($id, $prefix . 'source', true);
145
+		$subscription->source_id       = get_post_meta($id, $prefix . 'source_id', true);
146
+		$subscription->frequency       = get_post_meta($id, $prefix . 'frequency', true);
147
+		$subscription->interval        = get_post_meta($id, $prefix . 'interval', true);
148
+		$subscription->interval_period = get_post_meta($id, $prefix . 'interval_period', true);
149
+		$subscription->currency        = get_post_meta($id, $prefix . 'currency', true);
150
+		$subscription->amount          = get_post_meta($id, $prefix . 'amount', true);
151
+		$subscription->transaction_id  = get_post_meta($id, $prefix . 'transaction_id', true);
152
+		$subscription->status          = get_post_meta($id, $prefix . 'status', true);
153
+		$subscription->description     = get_post_meta($id, $prefix . 'description', true);
154
+		$subscription->email           = get_post_meta($id, $prefix . 'email', true);
155
+		$subscription->customer_name   = get_post_meta($id, $prefix . 'customer_name', true);
156
+		$subscription->payment_method  = get_post_meta($id, $prefix . 'payment_method', true);
157 157
 
158 158
 		$first_payment = $subscription->get_first_payment();
159 159
 
160
-		if ( is_object( $first_payment ) ) {
161
-			if ( empty( $subscription->config_id ) ) {
160
+		if (is_object($first_payment)) {
161
+			if (empty($subscription->config_id)) {
162 162
 				$subscription->config_id = $first_payment->config_id;
163 163
 			}
164 164
 
165
-			if ( empty( $subscription->user_id ) ) {
165
+			if (empty($subscription->user_id)) {
166 166
 				$subscription->user_id = $first_payment->user_id;
167 167
 			}
168 168
 
169
-			if ( empty( $subscription->payment_method ) ) {
169
+			if (empty($subscription->payment_method)) {
170 170
 				$subscription->payment_method = $first_payment->method;
171 171
 			}
172 172
 		}
173 173
 
174
-		$date_string              = get_post_meta( $id, $prefix . 'start_date', true );
175
-		$subscription->start_date = empty( $date_string ) ? null : new DateTime( $date_string );
174
+		$date_string              = get_post_meta($id, $prefix . 'start_date', true);
175
+		$subscription->start_date = empty($date_string) ? null : new DateTime($date_string);
176 176
 
177
-		$date_string               = get_post_meta( $id, $prefix . 'expiry_date', true );
178
-		$subscription->expiry_date = empty( $date_string ) ? null : new DateTime( $date_string );
177
+		$date_string               = get_post_meta($id, $prefix . 'expiry_date', true);
178
+		$subscription->expiry_date = empty($date_string) ? null : new DateTime($date_string);
179 179
 
180
-		$date_string                 = get_post_meta( $id, $prefix . 'first_payment', true );
181
-		$subscription->first_payment = empty( $date_string ) ? null : new DateTime( $date_string );
180
+		$date_string                 = get_post_meta($id, $prefix . 'first_payment', true);
181
+		$subscription->first_payment = empty($date_string) ? null : new DateTime($date_string);
182 182
 
183
-		$date_string                = get_post_meta( $id, $prefix . 'next_payment', true );
184
-		$subscription->next_payment = empty( $date_string ) ? null : new DateTime( $date_string );
183
+		$date_string                = get_post_meta($id, $prefix . 'next_payment', true);
184
+		$subscription->next_payment = empty($date_string) ? null : new DateTime($date_string);
185 185
 
186
-		$date_string                 = get_post_meta( $id, $prefix . 'final_payment', true );
187
-		$subscription->final_payment = empty( $date_string ) ? null : new DateTime( $date_string );
186
+		$date_string                 = get_post_meta($id, $prefix . 'final_payment', true);
187
+		$subscription->final_payment = empty($date_string) ? null : new DateTime($date_string);
188 188
 
189
-		$date_string                  = get_post_meta( $id, $prefix . 'renewal_notice', true );
190
-		$subscription->renewal_notice = empty( $date_string ) ? null : new DateTime( $date_string );
189
+		$date_string                  = get_post_meta($id, $prefix . 'renewal_notice', true);
190
+		$subscription->renewal_notice = empty($date_string) ? null : new DateTime($date_string);
191 191
 	}
192 192
 
193 193
 	/**
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
 	 * @see https://github.com/woocommerce/woocommerce/blob/3.2.6/includes/data-stores/class-wc-order-data-store-cpt.php#L154-L257
197 197
 	 * @param Subscription $subscription The subscription to update the post meta for.
198 198
 	 */
199
-	private function update_post_meta( $subscription ) {
199
+	private function update_post_meta($subscription) {
200 200
 		$prefix = '_pronamic_subscription_';
201 201
 
202 202
 		$id = $subscription->get_id();
203 203
 
204
-		$previous_status = get_post_meta( $id, '_pronamic_subscription_status', true );
205
-		$previous_status = strtolower( $previous_status );
206
-		$previous_status = empty( $previous_status ) ? 'unknown' : $previous_status;
204
+		$previous_status = get_post_meta($id, '_pronamic_subscription_status', true);
205
+		$previous_status = strtolower($previous_status);
206
+		$previous_status = empty($previous_status) ? 'unknown' : $previous_status;
207 207
 
208 208
 		$data = array(
209 209
 			'config_id'       => $subscription->config_id,
@@ -238,28 +238,28 @@  discard block
 block discarded – undo
238 238
 			'renewal_notice',
239 239
 		);
240 240
 
241
-		foreach ( $date_properties as $property ) {
242
-			if ( property_exists( $subscription, $property ) && $subscription->$property instanceof \DateTimeInterface ) {
243
-				$data[ $property ] = $subscription->$property->format( 'Y-m-d H:i:s' );
241
+		foreach ($date_properties as $property) {
242
+			if (property_exists($subscription, $property) && $subscription->$property instanceof \DateTimeInterface) {
243
+				$data[$property] = $subscription->$property->format('Y-m-d H:i:s');
244 244
 			}
245 245
 		}
246 246
 
247
-		$data = array_merge( $subscription->meta, $data );
247
+		$data = array_merge($subscription->meta, $data);
248 248
 
249
-		foreach ( $data as $key => $value ) {
250
-			if ( ! empty( $value ) ) {
249
+		foreach ($data as $key => $value) {
250
+			if ( ! empty($value)) {
251 251
 				$meta_key = $prefix . $key;
252 252
 
253
-				update_post_meta( $id, $meta_key, $value );
253
+				update_post_meta($id, $meta_key, $value);
254 254
 			}
255 255
 		}
256 256
 
257
-		if ( $previous_status !== $subscription->status ) {
257
+		if ($previous_status !== $subscription->status) {
258 258
 			$can_redirect = false;
259 259
 
260
-			do_action( 'pronamic_subscription_status_update_' . $subscription->source . '_' . strtolower( $previous_status ) . '_to_' . strtolower( $subscription->status ), $subscription, $can_redirect );
261
-			do_action( 'pronamic_subscription_status_update_' . $subscription->source, $subscription, $can_redirect );
262
-			do_action( 'pronamic_subscription_status_update', $subscription, $can_redirect );
260
+			do_action('pronamic_subscription_status_update_' . $subscription->source . '_' . strtolower($previous_status) . '_to_' . strtolower($subscription->status), $subscription, $can_redirect);
261
+			do_action('pronamic_subscription_status_update_' . $subscription->source, $subscription, $can_redirect);
262
+			do_action('pronamic_subscription_status_update', $subscription, $can_redirect);
263 263
 		}
264 264
 	}
265 265
 }
Please login to merge, or discard this patch.