Passed
Push — master ( c6f5be...d01f61 )
by Brian
14:12
created
includes/data-stores/class-getpaid-item-data-store.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Item_Data_Store class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -80,39 +80,39 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @param WPInv_Item $item Item object.
82 82
 	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time( 'mysql' ) );
83
+	public function create(&$item) {
84
+		$item->set_version(WPINV_VERSION);
85
+		$item->set_date_created(current_time('mysql'));
86 86
 
87 87
 		// Create a new post.
88 88
 		$id = wp_insert_post(
89 89
 			apply_filters(
90 90
 				'getpaid_new_item_data',
91 91
 				array(
92
-					'post_date'    => $item->get_date_created( 'edit' ),
92
+					'post_date'    => $item->get_date_created('edit'),
93 93
 					'post_type'    => 'wpi_item',
94
-					'post_status'  => $this->get_post_status( $item ),
94
+					'post_status'  => $this->get_post_status($item),
95 95
 					'ping_status'  => 'closed',
96
-					'post_author'  => $item->get_author( 'edit' ),
97
-					'post_title'   => $item->get_name( 'edit' ),
96
+					'post_author'  => $item->get_author('edit'),
97
+					'post_title'   => $item->get_name('edit'),
98 98
 					'post_parent'  => $item->get_parent_id(),
99
-					'post_excerpt' => $item->get_description( 'edit' ),
99
+					'post_excerpt' => $item->get_description('edit'),
100 100
 				)
101 101
 			),
102 102
 			true
103 103
 		);
104 104
 
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
105
+		if ($id && !is_wp_error($id)) {
106
+			$item->set_id($id);
107
+			$this->update_post_meta($item);
108 108
 			$item->save_meta_data();
109 109
 			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item );
110
+			$this->clear_caches($item);
111
+			do_action('getpaid_new_item', $item);
112 112
 			return true;
113 113
 		}
114 114
 
115
-		if ( is_wp_error( $id ) ) {
115
+		if (is_wp_error($id)) {
116 116
 			$item->last_error = $id->get_error_message();
117 117
 		}
118 118
 
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 	 * @param WPInv_Item $item Item object.
126 126
 	 *
127 127
 	 */
128
-	public function read( &$item ) {
128
+	public function read(&$item) {
129 129
 
130 130
 		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
131
+		$item_object = get_post($item->get_id());
132 132
 
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
135
-			$item->set_id( 0 );
133
+		if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') {
134
+			$item->last_error = __('Invalid item.', 'invoicing');
135
+			$item->set_id(0);
136 136
 			return false;
137 137
 		}
138 138
 
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
 			)
149 149
 		);
150 150
 
151
-		$this->read_object_data( $item, $item_object );
151
+		$this->read_object_data($item, $item_object);
152 152
 		$item->read_meta_data();
153
-		$item->set_object_read( true );
154
-		do_action( 'getpaid_read_item', $item );
153
+		$item->set_object_read(true);
154
+		do_action('getpaid_read_item', $item);
155 155
 
156 156
 	}
157 157
 
@@ -160,29 +160,29 @@  discard block
 block discarded – undo
160 160
 	 *
161 161
 	 * @param WPInv_Item $item Item object.
162 162
 	 */
163
-	public function update( &$item ) {
163
+	public function update(&$item) {
164 164
 		$item->save_meta_data();
165
-		$item->set_version( WPINV_VERSION );
165
+		$item->set_version(WPINV_VERSION);
166 166
 
167
-		if ( null === $item->get_date_created( 'edit' ) ) {
168
-			$item->set_date_created( current_time( 'mysql' ) );
167
+		if (null === $item->get_date_created('edit')) {
168
+			$item->set_date_created(current_time('mysql'));
169 169
 		}
170 170
 
171 171
 		// Grab the current status so we can compare.
172
-		$previous_status = get_post_status( $item->get_id() );
172
+		$previous_status = get_post_status($item->get_id());
173 173
 
174 174
 		$changes = $item->get_changes();
175 175
 
176 176
 		// Only update the post when the post data changes.
177
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author' ), array_keys( $changes ) ) ) {
177
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'description', 'name', 'author'), array_keys($changes))) {
178 178
 			$post_data = array(
179
-				'post_date'     => $item->get_date_created( 'edit' ),
180
-				'post_status'   => $item->get_status( 'edit' ),
181
-				'post_parent'   => $item->get_parent_id( 'edit' ),
182
-				'post_excerpt'  => $item->get_description( 'edit' ),
183
-				'post_modified' => $item->get_date_modified( 'edit' ),
184
-				'post_title'    => $item->get_name( 'edit' ),
185
-				'post_author'   => $item->get_author( 'edit' ),
179
+				'post_date'     => $item->get_date_created('edit'),
180
+				'post_status'   => $item->get_status('edit'),
181
+				'post_parent'   => $item->get_parent_id('edit'),
182
+				'post_excerpt'  => $item->get_description('edit'),
183
+				'post_modified' => $item->get_date_modified('edit'),
184
+				'post_title'    => $item->get_name('edit'),
185
+				'post_author'   => $item->get_author('edit'),
186 186
 			);
187 187
 
188 188
 			/**
@@ -193,25 +193,25 @@  discard block
 block discarded – undo
193 193
 			 * This ensures hooks are fired by either WP itself (admin screen save),
194 194
 			 * or an update purely from CRUD.
195 195
 			 */
196
-			if ( doing_action( 'save_post' ) ) {
197
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
198
-				clean_post_cache( $item->get_id() );
196
+			if (doing_action('save_post')) {
197
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id()));
198
+				clean_post_cache($item->get_id());
199 199
 			} else {
200
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
200
+				wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data));
201 201
 			}
202
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202
+			$item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
203 203
 		}
204
-		$this->update_post_meta( $item );
204
+		$this->update_post_meta($item);
205 205
 		$item->apply_changes();
206
-		$this->clear_caches( $item );
206
+		$this->clear_caches($item);
207 207
 
208 208
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
209
-		$new_status = $item->get_status( 'edit' );
209
+		$new_status = $item->get_status('edit');
210 210
 
211
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
212
-			do_action( 'getpaid_new_item', $item );
211
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
212
+			do_action('getpaid_new_item', $item);
213 213
 		} else {
214
-			do_action( 'getpaid_update_item', $item );
214
+			do_action('getpaid_update_item', $item);
215 215
 		}
216 216
 
217 217
 	}
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
 	 * @param WPInv_Item $item WPInv_Item object.
229 229
 	 * @since 1.0.19
230 230
 	 */
231
-	protected function update_post_meta( &$item ) {
231
+	protected function update_post_meta(&$item) {
232 232
 
233 233
 		// Ensure that we have a custom id.
234
-        if ( ! $item->get_custom_id() ) {
235
-            $item->set_custom_id( $item->get_id() );
234
+        if (!$item->get_custom_id()) {
235
+            $item->set_custom_id($item->get_id());
236 236
 		}
237 237
 
238
-		parent::update_post_meta( $item );
238
+		parent::update_post_meta($item);
239 239
 	}
240 240
 
241 241
 }
Please login to merge, or discard this patch.