Passed
Pull Request — master (#160)
by Jonathan
04:29
created
classes/salesforce_mapping.php 1 patch
Spacing   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @file
6 6
  */
7 7
 
8
-if ( ! class_exists( 'Object_Sync_Salesforce' ) ) {
8
+if ( ! class_exists('Object_Sync_Salesforce')) {
9 9
 	die();
10 10
 }
11 11
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 * @param object $logging Object_Sync_Sf_Logging.
61 61
 	 * @throws \Exception
62 62
 	 */
63
-	public function __construct( $wpdb, $version, $slug, $logging ) {
63
+	public function __construct($wpdb, $version, $slug, $logging) {
64 64
 		$this->wpdb    = $wpdb;
65 65
 		$this->version = $version;
66 66
 		$this->slug    = $slug;
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
 		$this->sync_sf_delete        = 0x0020;
84 84
 
85 85
 		// Define which events are initialized by which system.
86
-		$this->wordpress_events  = array( $this->sync_wordpress_create, $this->sync_wordpress_update, $this->sync_wordpress_delete );
87
-		$this->salesforce_events = array( $this->sync_sf_create, $this->sync_sf_update, $this->sync_sf_delete );
86
+		$this->wordpress_events  = array($this->sync_wordpress_create, $this->sync_wordpress_update, $this->sync_wordpress_delete);
87
+		$this->salesforce_events = array($this->sync_sf_create, $this->sync_sf_update, $this->sync_sf_delete);
88 88
 
89 89
 		// Constants for the directions to map things.
90 90
 		$this->direction_wordpress_sf = 'wp_sf';
91 91
 		$this->direction_sf_wordpress = 'sf_wp';
92 92
 		$this->direction_sync         = 'sync';
93 93
 
94
-		$this->direction_wordpress  = array( $this->direction_wordpress_sf, $this->direction_sync );
95
-		$this->direction_salesforce = array( $this->direction_sf_wordpress, $this->direction_sync );
94
+		$this->direction_wordpress  = array($this->direction_wordpress_sf, $this->direction_sync);
95
+		$this->direction_salesforce = array($this->direction_sf_wordpress, $this->direction_sync);
96 96
 
97 97
 		// This is used when we map a record with default or Master.
98 98
 		$this->salesforce_default_record_type = 'default';
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
 		// Salesforce has multipicklists and they have a delimiter.
101 101
 		$this->array_delimiter = ';';
102 102
 		// What data types in Salesforce should be an array?
103
-		$this->array_types_from_salesforce = array( 'multipicklist' );
103
+		$this->array_types_from_salesforce = array('multipicklist');
104 104
 		// What data types in Salesforce should be a date field?
105
-		$this->date_types_from_salesforce = array( 'date', 'datetime' );
105
+		$this->date_types_from_salesforce = array('date', 'datetime');
106 106
 		// What data types in Salesforce should be an integer?
107
-		$this->int_types_from_salesforce = array( 'integer', 'boolean' );
107
+		$this->int_types_from_salesforce = array('integer', 'boolean');
108 108
 
109 109
 		// Max length for a mapping field.
110 110
 		$this->name_length = 128;
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
 	 * @param array $salesforce_fields The fields for the Salesforce side of the mapping.
124 124
 	 * @throws \Exception
125 125
 	 */
126
-	public function create_fieldmap( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array() ) {
127
-		$data = $this->setup_fieldmap_data( $posted, $wordpress_fields, $salesforce_fields );
128
-		if ( version_compare( $this->version, '1.2.5', '>=' ) ) {
126
+	public function create_fieldmap($posted = array(), $wordpress_fields = array(), $salesforce_fields = array()) {
127
+		$data = $this->setup_fieldmap_data($posted, $wordpress_fields, $salesforce_fields);
128
+		if (version_compare($this->version, '1.2.5', '>=')) {
129 129
 			$data['version'] = $this->version;
130 130
 		}
131
-		$insert = $this->wpdb->insert( $this->fieldmap_table, $data );
132
-		if ( 1 === $insert ) {
131
+		$insert = $this->wpdb->insert($this->fieldmap_table, $data);
132
+		if (1 === $insert) {
133 133
 			return $this->wpdb->insert_id;
134 134
 		} else {
135 135
 			return false;
@@ -145,29 +145,29 @@  discard block
 block discarded – undo
145 145
 	 * @return Array $map a single mapping or $mappings, an array of mappings.
146 146
 	 * @throws \Exception
147 147
 	 */
148
-	public function get_fieldmaps( $id = null, $conditions = array(), $reset = false ) {
148
+	public function get_fieldmaps($id = null, $conditions = array(), $reset = false) {
149 149
 		$table = $this->fieldmap_table;
150
-		if ( null !== $id ) { // get one fieldmap.
151
-			$map                                    = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = ' . $id, ARRAY_A );
152
-			$map['salesforce_record_types_allowed'] = maybe_unserialize( $map['salesforce_record_types_allowed'] );
150
+		if (null !== $id) { // get one fieldmap.
151
+			$map                                    = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = ' . $id, ARRAY_A);
152
+			$map['salesforce_record_types_allowed'] = maybe_unserialize($map['salesforce_record_types_allowed']);
153 153
 
154
-			$map['fields']        = maybe_unserialize( $map['fields'] );
155
-			$map['sync_triggers'] = maybe_unserialize( $map['sync_triggers'] );
154
+			$map['fields']        = maybe_unserialize($map['fields']);
155
+			$map['sync_triggers'] = maybe_unserialize($map['sync_triggers']);
156 156
 			return $map;
157
-		} elseif ( ! empty( $conditions ) ) { // get multiple but with a limitation.
157
+		} elseif ( ! empty($conditions)) { // get multiple but with a limitation.
158 158
 			$mappings    = array();
159 159
 			$record_type = '';
160 160
 
161 161
 			// Assemble the SQL.
162
-			if ( ! empty( $conditions ) ) {
162
+			if ( ! empty($conditions)) {
163 163
 				$where = ' WHERE ';
164 164
 				$i     = 0;
165
-				foreach ( $conditions as $key => $value ) {
166
-					if ( 'salesforce_record_type' === $key ) {
167
-						$record_type = sanitize_text_field( $value );
165
+				foreach ($conditions as $key => $value) {
166
+					if ('salesforce_record_type' === $key) {
167
+						$record_type = sanitize_text_field($value);
168 168
 					} else {
169 169
 						$i++;
170
-						if ( $i > 1 ) {
170
+						if ($i > 1) {
171 171
 							$where .= ' AND ';
172 172
 						}
173 173
 						$where .= '`' . $key . '` = "' . $value . '"';
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 				$where = '';
178 178
 			}
179 179
 
180
-			$mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $where . ' ORDER BY `weight`', ARRAY_A );
180
+			$mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $where . ' ORDER BY `weight`', ARRAY_A);
181 181
 
182
-			if ( ! empty( $mappings ) ) {
183
-				$mappings = $this->prepare_fieldmap_data( $mappings, $record_type );
182
+			if ( ! empty($mappings)) {
183
+				$mappings = $this->prepare_fieldmap_data($mappings, $record_type);
184 184
 			}
185 185
 
186 186
 			return $mappings;
@@ -188,14 +188,14 @@  discard block
 block discarded – undo
188 188
 		} else { // get all of the mappings. ALL THE MAPPINGS.
189 189
 
190 190
 			// if the version is greater than or equal to 1.2.5, the fieldmap table has a version column
191
-			if ( version_compare( $this->version, '1.2.5', '>=' ) ) {
192
-				$mappings = $this->wpdb->get_results( "SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight`, `version` FROM $table", ARRAY_A );
191
+			if (version_compare($this->version, '1.2.5', '>=')) {
192
+				$mappings = $this->wpdb->get_results("SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight`, `version` FROM $table", ARRAY_A);
193 193
 			} else {
194
-				$mappings = $this->wpdb->get_results( "SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight` FROM $table", ARRAY_A );
194
+				$mappings = $this->wpdb->get_results("SELECT `id`, `label`, `wordpress_object`, `salesforce_object`, `salesforce_record_types_allowed`, `salesforce_record_type_default`, `fields`, `pull_trigger_field`, `sync_triggers`, `push_async`, `push_drafts`, `weight` FROM $table", ARRAY_A);
195 195
 			}
196 196
 
197
-			if ( ! empty( $mappings ) ) {
198
-				$mappings = $this->prepare_fieldmap_data( $mappings );
197
+			if ( ! empty($mappings)) {
198
+				$mappings = $this->prepare_fieldmap_data($mappings);
199 199
 			}
200 200
 
201 201
 			return $mappings;
@@ -211,29 +211,29 @@  discard block
 block discarded – undo
211 211
 	 *
212 212
 	 * @return Array of mapped fields
213 213
 	 */
214
-	public function get_mapped_fields( $mapping, $directions = array() ) {
214
+	public function get_mapped_fields($mapping, $directions = array()) {
215 215
 		$mapped_fields = array();
216
-		foreach ( $mapping['fields'] as $fields ) {
217
-			if ( empty( $directions ) || in_array( $fields['direction'], $directions, true ) ) {
216
+		foreach ($mapping['fields'] as $fields) {
217
+			if (empty($directions) || in_array($fields['direction'], $directions, true)) {
218 218
 
219
-				if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fields['salesforce_field']['name'] ) ) {
219
+				if (version_compare($this->version, '1.2.0', '>=') && isset($fields['salesforce_field']['name'])) {
220 220
 					$array_key = 'name';
221 221
 				} else {
222 222
 					$array_key = 'label';
223 223
 				}
224 224
 
225 225
 				// Some field map types (Relation) store a collection of SF objects.
226
-				if ( is_array( $fields['salesforce_field'] ) && ! isset( $fields['salesforce_field'][ $array_key ] ) ) {
227
-					foreach ( $fields['salesforce_field'] as $sf_field ) {
228
-						$mapped_fields[ $sf_field[ $array_key ] ] = $sf_field[ $array_key ];
226
+				if (is_array($fields['salesforce_field']) && ! isset($fields['salesforce_field'][$array_key])) {
227
+					foreach ($fields['salesforce_field'] as $sf_field) {
228
+						$mapped_fields[$sf_field[$array_key]] = $sf_field[$array_key];
229 229
 					}
230 230
 				} else { // The rest are just a name/value pair.
231
-					$mapped_fields[ $fields['salesforce_field'][ $array_key ] ] = $fields['salesforce_field'][ $array_key ];
231
+					$mapped_fields[$fields['salesforce_field'][$array_key]] = $fields['salesforce_field'][$array_key];
232 232
 				}
233 233
 			}
234 234
 		}
235 235
 
236
-		if ( ! empty( $this->get_mapped_record_types ) ) {
236
+		if ( ! empty($this->get_mapped_record_types)) {
237 237
 			$mapped_fields['RecordTypeId'] = 'RecordTypeId';
238 238
 		}
239 239
 
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
 	 * @param Array $mapping A mapping from which we wish to estract the record type.
247 247
 	 * @return Array of mappings. Empty if the mapping's record type is default, else full of the record types.
248 248
 	 */
249
-	public function get_mapped_record_types( $mapping ) {
250
-		return $mapping['salesforce_record_type_default'] === $this->salesforce_default_record_type ? array() : array_filter( maybe_unserialize( $mapping['salesforce_record_types_allowed'] ) );
249
+	public function get_mapped_record_types($mapping) {
250
+		return $mapping['salesforce_record_type_default'] === $this->salesforce_default_record_type ? array() : array_filter(maybe_unserialize($mapping['salesforce_record_types_allowed']));
251 251
 	}
252 252
 
253 253
 	/**
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	 * @return $map
261 261
 	 * @throws \Exception
262 262
 	 */
263
-	public function update_fieldmap( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array(), $id = '' ) {
264
-		$data = $this->setup_fieldmap_data( $posted, $wordpress_fields, $salesforce_fields );
265
-		if ( version_compare( $this->version, '1.2.5', '>=' ) && ! isset( $data['updated'] ) ) {
263
+	public function update_fieldmap($posted = array(), $wordpress_fields = array(), $salesforce_fields = array(), $id = '') {
264
+		$data = $this->setup_fieldmap_data($posted, $wordpress_fields, $salesforce_fields);
265
+		if (version_compare($this->version, '1.2.5', '>=') && ! isset($data['updated'])) {
266 266
 			$data['version'] = $this->version;
267 267
 		}
268 268
 		$update = $this->wpdb->update(
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 				'id' => $id,
273 273
 			)
274 274
 		);
275
-		if ( false === $update ) {
275
+		if (false === $update) {
276 276
 			return false;
277 277
 		} else {
278 278
 			return true;
@@ -288,76 +288,76 @@  discard block
 block discarded – undo
288 288
 	 * @param array $salesforce_fields The fields for the Salesforce side of the mapping.
289 289
 	 * @return $data
290 290
 	 */
291
-	private function setup_fieldmap_data( $posted = array(), $wordpress_fields = array(), $salesforce_fields = array() ) {
291
+	private function setup_fieldmap_data($posted = array(), $wordpress_fields = array(), $salesforce_fields = array()) {
292 292
 		$data = array(
293 293
 			'label'             => $posted['label'],
294
-			'name'              => sanitize_title( $posted['label'] ),
294
+			'name'              => sanitize_title($posted['label']),
295 295
 			'salesforce_object' => $posted['salesforce_object'],
296 296
 			'wordpress_object'  => $posted['wordpress_object'],
297 297
 		);
298
-		if ( isset( $posted['wordpress_field'] ) && is_array( $posted['wordpress_field'] ) && isset( $posted['salesforce_field'] ) && is_array( $posted['salesforce_field'] ) ) {
298
+		if (isset($posted['wordpress_field']) && is_array($posted['wordpress_field']) && isset($posted['salesforce_field']) && is_array($posted['salesforce_field'])) {
299 299
 			$setup['fields'] = array();
300
-			foreach ( $posted['wordpress_field'] as $key => $value ) {
301
-				$method_key = array_search( $value, array_column( $wordpress_fields, 'key' ), true );
302
-				if ( ! isset( $posted['direction'][ $key ] ) ) {
303
-					$posted['direction'][ $key ] = 'sync';
300
+			foreach ($posted['wordpress_field'] as $key => $value) {
301
+				$method_key = array_search($value, array_column($wordpress_fields, 'key'), true);
302
+				if ( ! isset($posted['direction'][$key])) {
303
+					$posted['direction'][$key] = 'sync';
304 304
 				}
305
-				if ( ! isset( $posted['is_prematch'][ $key ] ) ) {
306
-					$posted['is_prematch'][ $key ] = false;
305
+				if ( ! isset($posted['is_prematch'][$key])) {
306
+					$posted['is_prematch'][$key] = false;
307 307
 				}
308
-				if ( ! isset( $posted['is_key'][ $key ] ) ) {
309
-					$posted['is_key'][ $key ] = false;
308
+				if ( ! isset($posted['is_key'][$key])) {
309
+					$posted['is_key'][$key] = false;
310 310
 				}
311
-				if ( ! isset( $posted['is_delete'][ $key ] ) ) {
312
-					$posted['is_delete'][ $key ] = false;
311
+				if ( ! isset($posted['is_delete'][$key])) {
312
+					$posted['is_delete'][$key] = false;
313 313
 				}
314
-				if ( false === $posted['is_delete'][ $key ] ) {
314
+				if (false === $posted['is_delete'][$key]) {
315 315
 					// I think it's good to over-mention that updateable is really how the Salesforce api spells it.
316
-					$updateable_key = array_search( $posted['salesforce_field'][ $key ], array_column( $salesforce_fields, 'name' ), true );
316
+					$updateable_key = array_search($posted['salesforce_field'][$key], array_column($salesforce_fields, 'name'), true);
317 317
 
318 318
 					$salesforce_field_attributes = array();
319
-					foreach ( $salesforce_fields[ $updateable_key ] as $sf_key => $sf_value ) {
320
-						if ( isset( $sf_value ) && ! is_array( $sf_value ) ) {
321
-							$salesforce_field_attributes[ $sf_key ] = esc_attr( $sf_value );
322
-						} elseif ( ! empty( $sf_value ) && is_array( $sf_value ) ) {
323
-							$salesforce_field_attributes[ $sf_key ] = maybe_unserialize( $sf_value );
319
+					foreach ($salesforce_fields[$updateable_key] as $sf_key => $sf_value) {
320
+						if (isset($sf_value) && ! is_array($sf_value)) {
321
+							$salesforce_field_attributes[$sf_key] = esc_attr($sf_value);
322
+						} elseif ( ! empty($sf_value) && is_array($sf_value)) {
323
+							$salesforce_field_attributes[$sf_key] = maybe_unserialize($sf_value);
324 324
 						} else {
325
-							$salesforce_field_attributes[ $sf_key ] = '';
325
+							$salesforce_field_attributes[$sf_key] = '';
326 326
 						}
327 327
 					}
328 328
 
329
-					$setup['fields'][ $key ] = array(
329
+					$setup['fields'][$key] = array(
330 330
 						'wordpress_field'  => array(
331
-							'label'   => sanitize_text_field( $posted['wordpress_field'][ $key ] ),
332
-							'methods' => maybe_unserialize( $wordpress_fields[ $method_key ]['methods'] ),
333
-							'type'    => isset( $wordpress_fields[ $method_key ]['type'] ) ? sanitize_text_field( $wordpress_fields[ $method_key ]['type'] ) : 'text',
331
+							'label'   => sanitize_text_field($posted['wordpress_field'][$key]),
332
+							'methods' => maybe_unserialize($wordpress_fields[$method_key]['methods']),
333
+							'type'    => isset($wordpress_fields[$method_key]['type']) ? sanitize_text_field($wordpress_fields[$method_key]['type']) : 'text',
334 334
 						),
335 335
 						'salesforce_field' => $salesforce_field_attributes,
336
-						'is_prematch'      => sanitize_text_field( $posted['is_prematch'][ $key ] ),
337
-						'is_key'           => sanitize_text_field( $posted['is_key'][ $key ] ),
338
-						'direction'        => sanitize_text_field( $posted['direction'][ $key ] ),
339
-						'is_delete'        => sanitize_text_field( $posted['is_delete'][ $key ] ),
336
+						'is_prematch'      => sanitize_text_field($posted['is_prematch'][$key]),
337
+						'is_key'           => sanitize_text_field($posted['is_key'][$key]),
338
+						'direction'        => sanitize_text_field($posted['direction'][$key]),
339
+						'is_delete'        => sanitize_text_field($posted['is_delete'][$key]),
340 340
 					);
341 341
 
342 342
 					// If the WordPress key or the Salesforce key are blank, remove this incomplete mapping.
343 343
 					// This prevents https://github.com/MinnPost/object-sync-for-salesforce/issues/82 .
344 344
 					if (
345
-						empty( $setup['fields'][ $key ]['wordpress_field']['label'] )
345
+						empty($setup['fields'][$key]['wordpress_field']['label'])
346 346
 						||
347
-						empty( $setup['fields'][ $key ]['salesforce_field']['name'] )
347
+						empty($setup['fields'][$key]['salesforce_field']['name'])
348 348
 					) {
349
-						unset( $setup['fields'][ $key ] );
349
+						unset($setup['fields'][$key]);
350 350
 					}
351 351
 				}
352 352
 			} // End foreach() on WordPress fields.
353
-			$data['fields'] = maybe_serialize( $setup['fields'] );
354
-		} elseif ( isset( $posted['fields'] ) && is_array( $posted['fields'] ) ) {
353
+			$data['fields'] = maybe_serialize($setup['fields']);
354
+		} elseif (isset($posted['fields']) && is_array($posted['fields'])) {
355 355
 			// if $posted['fields'] is already set, use that
356
-			$data['fields'] = maybe_serialize( $posted['fields'] );
356
+			$data['fields'] = maybe_serialize($posted['fields']);
357 357
 		} // End if() WordPress fields are present.
358 358
 
359
-		if ( isset( $posted['salesforce_record_types_allowed'] ) ) {
360
-			$data['salesforce_record_types_allowed'] = maybe_serialize( $posted['salesforce_record_types_allowed'] );
359
+		if (isset($posted['salesforce_record_types_allowed'])) {
360
+			$data['salesforce_record_types_allowed'] = maybe_serialize($posted['salesforce_record_types_allowed']);
361 361
 		} else {
362 362
 			$data['salesforce_record_types_allowed'] = maybe_serialize(
363 363
 				array(
@@ -365,29 +365,29 @@  discard block
 block discarded – undo
365 365
 				)
366 366
 			);
367 367
 		}
368
-		if ( isset( $posted['salesforce_record_type_default'] ) ) {
368
+		if (isset($posted['salesforce_record_type_default'])) {
369 369
 			$data['salesforce_record_type_default'] = $posted['salesforce_record_type_default'];
370 370
 		} else {
371
-			$data['salesforce_record_type_default'] = maybe_serialize( $this->salesforce_default_record_type );
371
+			$data['salesforce_record_type_default'] = maybe_serialize($this->salesforce_default_record_type);
372 372
 		}
373
-		if ( isset( $posted['pull_trigger_field'] ) ) {
373
+		if (isset($posted['pull_trigger_field'])) {
374 374
 			$data['pull_trigger_field'] = $posted['pull_trigger_field'];
375 375
 		}
376
-		if ( isset( $posted['sync_triggers'] ) && is_array( $posted['sync_triggers'] ) ) {
376
+		if (isset($posted['sync_triggers']) && is_array($posted['sync_triggers'])) {
377 377
 			$setup['sync_triggers'] = array();
378
-			foreach ( $posted['sync_triggers'] as $key => $value ) {
379
-				$setup['sync_triggers'][ $key ] = esc_html( $posted['sync_triggers'][ $key ] );
378
+			foreach ($posted['sync_triggers'] as $key => $value) {
379
+				$setup['sync_triggers'][$key] = esc_html($posted['sync_triggers'][$key]);
380 380
 			}
381 381
 		} else {
382 382
 			$setup['sync_triggers'] = array();
383 383
 		}
384
-		$data['sync_triggers'] = maybe_serialize( $setup['sync_triggers'] );
385
-		if ( isset( $posted['pull_trigger_field'] ) ) {
384
+		$data['sync_triggers'] = maybe_serialize($setup['sync_triggers']);
385
+		if (isset($posted['pull_trigger_field'])) {
386 386
 			$data['pull_trigger_field'] = $posted['pull_trigger_field'];
387 387
 		}
388
-		$data['push_async']  = isset( $posted['push_async'] ) ? $posted['push_async'] : '';
389
-		$data['push_drafts'] = isset( $posted['push_drafts'] ) ? $posted['push_drafts'] : '';
390
-		$data['weight']      = isset( $posted['weight'] ) ? $posted['weight'] : '';
388
+		$data['push_async']  = isset($posted['push_async']) ? $posted['push_async'] : '';
389
+		$data['push_drafts'] = isset($posted['push_drafts']) ? $posted['push_drafts'] : '';
390
+		$data['weight']      = isset($posted['weight']) ? $posted['weight'] : '';
391 391
 		return $data;
392 392
 	}
393 393
 
@@ -398,12 +398,12 @@  discard block
 block discarded – undo
398 398
 	 * @return Boolean
399 399
 	 * @throws \Exception
400 400
 	 */
401
-	public function delete_fieldmap( $id = '' ) {
401
+	public function delete_fieldmap($id = '') {
402 402
 		$data   = array(
403 403
 			'id' => $id,
404 404
 		);
405
-		$delete = $this->wpdb->delete( $this->fieldmap_table, $data );
406
-		if ( 1 === $delete ) {
405
+		$delete = $this->wpdb->delete($this->fieldmap_table, $data);
406
+		if (1 === $delete) {
407 407
 			return true;
408 408
 		} else {
409 409
 			return false;
@@ -417,27 +417,27 @@  discard block
 block discarded – undo
417 417
 	 * @return false|Int of field mapping between WordPress and Salesforce objects
418 418
 	 * @throws \Exception
419 419
 	 */
420
-	public function create_object_map( $posted = array() ) {
421
-		$data            = $this->setup_object_map_data( $posted );
422
-		$data['created'] = current_time( 'mysql' );
420
+	public function create_object_map($posted = array()) {
421
+		$data            = $this->setup_object_map_data($posted);
422
+		$data['created'] = current_time('mysql');
423 423
 		// Check to see if we don't know the salesforce id and it is not a temporary id, or if this is pending.
424 424
 		// If it is using a temporary id, the map will get updated after it finishes running; it won't call this method unless there's an error, which we should log.
425
-		if ( substr( $data['salesforce_id'], 0, 7 ) !== 'tmp_sf_' || 'pending' === $data['action'] ) {
426
-			unset( $data['action'] );
427
-			$insert = $this->wpdb->insert( $this->object_map_table, $data );
425
+		if (substr($data['salesforce_id'], 0, 7) !== 'tmp_sf_' || 'pending' === $data['action']) {
426
+			unset($data['action']);
427
+			$insert = $this->wpdb->insert($this->object_map_table, $data);
428 428
 		} else {
429 429
 			$status = 'error';
430
-			if ( isset( $this->logging ) ) {
430
+			if (isset($this->logging)) {
431 431
 				$logging = $this->logging;
432
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
433
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
432
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
433
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
434 434
 			}
435 435
 			$logging->setup(
436 436
 				sprintf(
437 437
 					// translators: %1$s is the name of a WordPress object. %2$s is the id of that object.
438
-					esc_html__( 'Error Mapping: error caused by trying to map the WordPress %1$s with ID of %2$s to Salesforce ID starting with "tmp_sf_", which is invalid.', 'object-sync-for-salesforce' ),
439
-					esc_attr( $data['wordpress_object'] ),
440
-					absint( $data['wordpress_id'] )
438
+					esc_html__('Error Mapping: error caused by trying to map the WordPress %1$s with ID of %2$s to Salesforce ID starting with "tmp_sf_", which is invalid.', 'object-sync-for-salesforce'),
439
+					esc_attr($data['wordpress_object']),
440
+					absint($data['wordpress_id'])
441 441
 				),
442 442
 				'',
443 443
 				0,
@@ -446,23 +446,23 @@  discard block
 block discarded – undo
446 446
 			);
447 447
 			return false;
448 448
 		}
449
-		if ( 1 === $insert ) {
449
+		if (1 === $insert) {
450 450
 			return $this->wpdb->insert_id;
451
-		} elseif ( false !== strpos( $this->wpdb->last_error, 'Duplicate entry' ) ) {
452
-			$mapping = $this->load_by_salesforce( $data['salesforce_id'] );
451
+		} elseif (false !== strpos($this->wpdb->last_error, 'Duplicate entry')) {
452
+			$mapping = $this->load_by_salesforce($data['salesforce_id']);
453 453
 			$id      = $mapping['id'];
454 454
 			$status  = 'error';
455
-			if ( isset( $this->logging ) ) {
455
+			if (isset($this->logging)) {
456 456
 				$logging = $this->logging;
457
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
458
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
457
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
458
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
459 459
 			}
460 460
 			$logging->setup(
461 461
 				sprintf(
462 462
 					// translators: %1$s is the status word "Error". %1$s is the Id of a Salesforce object. %2$s is the ID of a mapping object.
463
-					esc_html__( 'Error: Mapping: there is already a WordPress object mapped to the Salesforce object %1$s and the mapping object ID is %2$s', 'object-sync-for-salesforce' ),
464
-					esc_attr( $data['salesforce_id'] ),
465
-					absint( $id )
463
+					esc_html__('Error: Mapping: there is already a WordPress object mapped to the Salesforce object %1$s and the mapping object ID is %2$s', 'object-sync-for-salesforce'),
464
+					esc_attr($data['salesforce_id']),
465
+					absint($id)
466 466
 				),
467 467
 				'',
468 468
 				0,
@@ -483,18 +483,18 @@  discard block
 block discarded – undo
483 483
 	 * @return $map or $mappings
484 484
 	 * @throws \Exception
485 485
 	 */
486
-	public function get_object_maps( $conditions = array(), $reset = false ) {
486
+	public function get_object_maps($conditions = array(), $reset = false) {
487 487
 		$table = $this->object_map_table;
488 488
 		$order = ' ORDER BY object_updated, created';
489
-		if ( ! empty( $conditions ) ) { // get multiple but with a limitation.
489
+		if ( ! empty($conditions)) { // get multiple but with a limitation.
490 490
 			$mappings = array();
491 491
 
492
-			if ( ! empty( $conditions ) ) {
492
+			if ( ! empty($conditions)) {
493 493
 				$where = ' WHERE ';
494 494
 				$i     = 0;
495
-				foreach ( $conditions as $key => $value ) {
495
+				foreach ($conditions as $key => $value) {
496 496
 					$i++;
497
-					if ( $i > 1 ) {
497
+					if ($i > 1) {
498 498
 						$where .= ' AND ';
499 499
 					}
500 500
 					$where .= '`' . $key . '` = "' . $value . '"';
@@ -503,13 +503,13 @@  discard block
 block discarded – undo
503 503
 				$where = '';
504 504
 			}
505 505
 
506
-			$mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $where . $order, ARRAY_A );
507
-			if ( ! empty( $mappings ) && 1 === $this->wpdb->num_rows ) {
506
+			$mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $where . $order, ARRAY_A);
507
+			if ( ! empty($mappings) && 1 === $this->wpdb->num_rows) {
508 508
 				$mappings = $mappings[0];
509 509
 			}
510 510
 		} else { // get all of the mappings. ALL THE MAPPINGS.
511
-			$mappings = $this->wpdb->get_results( 'SELECT * FROM ' . $table . $order, ARRAY_A );
512
-			if ( ! empty( $mappings ) && 1 === $this->wpdb->num_rows ) {
511
+			$mappings = $this->wpdb->get_results('SELECT * FROM ' . $table . $order, ARRAY_A);
512
+			if ( ! empty($mappings) && 1 === $this->wpdb->num_rows) {
513 513
 				$mappings = $mappings[0];
514 514
 			}
515 515
 		}
@@ -526,10 +526,10 @@  discard block
 block discarded – undo
526 526
 	 * @return $map
527 527
 	 * @throws \Exception
528 528
 	 */
529
-	public function update_object_map( $posted = array(), $id = '' ) {
530
-		$data = $this->setup_object_map_data( $posted );
531
-		if ( ! isset( $data['object_updated'] ) ) {
532
-			$data['object_updated'] = current_time( 'mysql' );
529
+	public function update_object_map($posted = array(), $id = '') {
530
+		$data = $this->setup_object_map_data($posted);
531
+		if ( ! isset($data['object_updated'])) {
532
+			$data['object_updated'] = current_time('mysql');
533 533
 		}
534 534
 		$update = $this->wpdb->update(
535 535
 			$this->object_map_table,
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				'id' => $id,
539 539
 			)
540 540
 		);
541
-		if ( false === $update ) {
541
+		if (false === $update) {
542 542
 			return false;
543 543
 		} else {
544 544
 			return true;
@@ -551,11 +551,11 @@  discard block
 block discarded – undo
551 551
 	 * @param array $posted It's $_POST.
552 552
 	 * @return $data Filtered array with only the keys that are in the object map database table. Strips out things from WordPress form if they're present.
553 553
 	 */
554
-	private function setup_object_map_data( $posted = array() ) {
555
-		$allowed_fields   = $this->wpdb->get_col( "DESC {$this->object_map_table}", 0 );
554
+	private function setup_object_map_data($posted = array()) {
555
+		$allowed_fields   = $this->wpdb->get_col("DESC {$this->object_map_table}", 0);
556 556
 		$allowed_fields[] = 'action'; // we use this in both directions even though it isn't in the database; we remove it from the array later if it is present
557 557
 
558
-		$data = array_intersect_key( $posted, array_flip( $allowed_fields ) );
558
+		$data = array_intersect_key($posted, array_flip($allowed_fields));
559 559
 		return $data;
560 560
 	}
561 561
 
@@ -565,12 +565,12 @@  discard block
 block discarded – undo
565 565
 	 * @param array $id The ID of the object map row.
566 566
 	 * @throws \Exception
567 567
 	 */
568
-	public function delete_object_map( $id = '' ) {
568
+	public function delete_object_map($id = '') {
569 569
 		$data   = array(
570 570
 			'id' => $id,
571 571
 		);
572
-		$delete = $this->wpdb->delete( $this->object_map_table, $data );
573
-		if ( 1 === $delete ) {
572
+		$delete = $this->wpdb->delete($this->object_map_table, $data);
573
+		if (1 === $delete) {
574 574
 			return true;
575 575
 		} else {
576 576
 			return false;
@@ -583,13 +583,13 @@  discard block
 block discarded – undo
583 583
 	 * @param string $direction Whether this is part of a push or pull action
584 584
 	 * @return $id is a temporary string that will be replaced if the modification is successful
585 585
 	 */
586
-	public function generate_temporary_id( $direction ) {
587
-		if ( 'push' === $direction ) {
586
+	public function generate_temporary_id($direction) {
587
+		if ('push' === $direction) {
588 588
 			$prefix = 'tmp_sf_';
589
-		} elseif ( 'pull' === $direction ) {
589
+		} elseif ('pull' === $direction) {
590 590
 			$prefix = 'tmp_wp_';
591 591
 		}
592
-		$id = uniqid( $prefix, true );
592
+		$id = uniqid($prefix, true);
593 593
 		return $id;
594 594
 	}
595 595
 
@@ -603,12 +603,12 @@  discard block
 block discarded – undo
603 603
 	 * @return SalesforceMappingObject
604 604
 	 *   The requested SalesforceMappingObject or FALSE if none was found.
605 605
 	 */
606
-	public function load_by_wordpress( $object_type, $object_id, $reset = false ) {
606
+	public function load_by_wordpress($object_type, $object_id, $reset = false) {
607 607
 		$conditions = array(
608 608
 			'wordpress_id'     => $object_id,
609 609
 			'wordpress_object' => $object_type,
610 610
 		);
611
-		return $this->get_object_maps( $conditions, $reset );
611
+		return $this->get_object_maps($conditions, $reset);
612 612
 	}
613 613
 
614 614
 	/**
@@ -620,24 +620,24 @@  discard block
 block discarded – undo
620 620
 	 * @return array $map
621 621
 	 *   The most recent fieldmap
622 622
 	 */
623
-	public function load_by_salesforce( $salesforce_id, $reset = false ) {
623
+	public function load_by_salesforce($salesforce_id, $reset = false) {
624 624
 		$conditions = array(
625 625
 			'salesforce_id' => $salesforce_id,
626 626
 		);
627 627
 
628
-		$map = $this->get_object_maps( $conditions, $reset );
628
+		$map = $this->get_object_maps($conditions, $reset);
629 629
 
630
-		if ( isset( $map[0] ) && is_array( $map[0] ) && count( $map ) > 1 ) {
630
+		if (isset($map[0]) && is_array($map[0]) && count($map) > 1) {
631 631
 			$status = 'notice';
632 632
 			$log    = '';
633 633
 			$log   .= 'Mapping: there is more than one mapped WordPress object for the Salesforce object ' . $salesforce_id . '. These WordPress IDs are: ';
634 634
 			$i      = 0;
635
-			foreach ( $map as $mapping ) {
635
+			foreach ($map as $mapping) {
636 636
 				$i++;
637
-				if ( isset( $mapping['wordpress_id'] ) ) {
637
+				if (isset($mapping['wordpress_id'])) {
638 638
 					$log .= 'object type: ' . $mapping['wordpress_object'] . ', id: ' . $mapping['wordpress_id'];
639 639
 				}
640
-				if ( count( $map ) !== $i ) {
640
+				if (count($map) !== $i) {
641 641
 					$log .= '; ';
642 642
 				} else {
643 643
 					$log .= '.';
@@ -645,16 +645,16 @@  discard block
 block discarded – undo
645 645
 			}
646 646
 			$map = $map[0];
647 647
 			// Create log entry for multiple maps.
648
-			if ( isset( $this->logging ) ) {
648
+			if (isset($this->logging)) {
649 649
 				$logging = $this->logging;
650
-			} elseif ( class_exists( 'Object_Sync_Sf_Logging' ) ) {
651
-				$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version );
650
+			} elseif (class_exists('Object_Sync_Sf_Logging')) {
651
+				$logging = new Object_Sync_Sf_Logging($this->wpdb, $this->version);
652 652
 			}
653 653
 			$logging->setup(
654 654
 				sprintf(
655 655
 					// translators: %1$s is the Id of a Salesforce object.
656
-					esc_html__( 'Notice: Mapping: there is more than one mapped WordPress object for the Salesforce object %2$s', 'object-sync-for-salesforce' ),
657
-					esc_attr( $salesforce_id )
656
+					esc_html__('Notice: Mapping: there is more than one mapped WordPress object for the Salesforce object %2$s', 'object-sync-for-salesforce'),
657
+					esc_attr($salesforce_id)
658 658
 				),
659 659
 				$log,
660 660
 				0,
@@ -677,33 +677,33 @@  discard block
 block discarded – undo
677 677
 	 *
678 678
 	 * @return array Associative array of key value pairs.
679 679
 	 */
680
-	public function map_params( $mapping, $object, $trigger, $use_soap = false, $is_new = true ) {
680
+	public function map_params($mapping, $object, $trigger, $use_soap = false, $is_new = true) {
681 681
 
682 682
 		$params = array();
683 683
 
684
-		foreach ( $mapping['fields'] as $fieldmap ) {
684
+		foreach ($mapping['fields'] as $fieldmap) {
685 685
 
686
-			$wordpress_haystack  = array_values( $this->wordpress_events );
687
-			$salesforce_haystack = array_values( $this->salesforce_events );
686
+			$wordpress_haystack  = array_values($this->wordpress_events);
687
+			$salesforce_haystack = array_values($this->salesforce_events);
688 688
 
689
-			$fieldmap['wordpress_field']['methods'] = maybe_unserialize( $fieldmap['wordpress_field']['methods'] );
689
+			$fieldmap['wordpress_field']['methods'] = maybe_unserialize($fieldmap['wordpress_field']['methods']);
690 690
 
691 691
 			// todo: we should think about whether this needs to be moved to after the key/prematching?
692 692
 			// skip fields that aren't being pushed to Salesforce.
693
-			if ( in_array( $trigger, $wordpress_haystack, true ) && ! in_array( $fieldmap['direction'], array_values( $this->direction_wordpress ), true ) ) {
693
+			if (in_array($trigger, $wordpress_haystack, true) && ! in_array($fieldmap['direction'], array_values($this->direction_wordpress), true)) {
694 694
 				// The trigger is a WordPress trigger, but the fieldmap direction is not a WordPress direction.
695 695
 				continue;
696 696
 			}
697 697
 
698 698
 			// skip fields that aren't being pulled from Salesforce.
699
-			if ( in_array( $trigger, $salesforce_haystack, true ) && ! in_array( $fieldmap['direction'], array_values( $this->direction_salesforce ), true ) ) {
699
+			if (in_array($trigger, $salesforce_haystack, true) && ! in_array($fieldmap['direction'], array_values($this->direction_salesforce), true)) {
700 700
 				// The trigger is a Salesforce trigger, but the fieldmap direction is not a Salesforce direction.
701 701
 				continue;
702 702
 			}
703 703
 
704 704
 			$wordpress_field = $fieldmap['wordpress_field']['label'];
705 705
 
706
-			if ( version_compare( $this->version, '1.2.0', '>=' ) && isset( $fieldmap['salesforce_field']['name'] ) ) {
706
+			if (version_compare($this->version, '1.2.0', '>=') && isset($fieldmap['salesforce_field']['name'])) {
707 707
 				$salesforce_field = $fieldmap['salesforce_field']['name'];
708 708
 				// Load the type of the Salesforce field. We can use this to handle Salesforce field value issues that come up based on what the field sends into WordPress or expects from WordPress.
709 709
 				$salesforce_field_type = $fieldmap['salesforce_field']['type'];
@@ -712,116 +712,116 @@  discard block
 block discarded – undo
712 712
 			}
713 713
 
714 714
 			// A WordPress event caused this.
715
-			if ( in_array( $trigger, array_values( $wordpress_haystack ), true ) ) {
715
+			if (in_array($trigger, array_values($wordpress_haystack), true)) {
716 716
 
717 717
 				// Is the field in WordPress an array, if we unserialize it? Salesforce wants it to be an imploded string.
718
-				if ( is_array( maybe_unserialize( $object[ $wordpress_field ] ) ) ) {
719
-					$object[ $wordpress_field ] = implode( $this->array_delimiter, $object[ $wordpress_field ] );
718
+				if (is_array(maybe_unserialize($object[$wordpress_field]))) {
719
+					$object[$wordpress_field] = implode($this->array_delimiter, $object[$wordpress_field]);
720 720
 				}
721 721
 
722
-				if ( isset( $salesforce_field_type ) ) {
722
+				if (isset($salesforce_field_type)) {
723 723
 					// Is the Salesforce field a date, and is the WordPress value a valid date?
724 724
 					// According to https://salesforce.stackexchange.com/questions/57032/date-format-with-salesforce-rest-api
725
-					if ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ) {
726
-						if ( '' === $object[ $wordpress_field ] ) {
727
-							$object[ $wordpress_field ] = null;
725
+					if (in_array($salesforce_field_type, $this->date_types_from_salesforce)) {
726
+						if ('' === $object[$wordpress_field]) {
727
+							$object[$wordpress_field] = null;
728 728
 						} else {
729
-							if ( false !== strtotime( $object[ $wordpress_field ] ) ) {
730
-								$timestamp = strtotime( $object[ $wordpress_field ] );
729
+							if (false !== strtotime($object[$wordpress_field])) {
730
+								$timestamp = strtotime($object[$wordpress_field]);
731 731
 							} else {
732
-								$timestamp = $object[ $wordpress_field ];
732
+								$timestamp = $object[$wordpress_field];
733 733
 							}
734
-							if ( 'datetime' === $salesforce_field_type ) {
735
-								$object[ $wordpress_field ] = date_i18n( 'c', $timestamp );
734
+							if ('datetime' === $salesforce_field_type) {
735
+								$object[$wordpress_field] = date_i18n('c', $timestamp);
736 736
 							} else {
737
-								$object[ $wordpress_field ] = date_i18n( 'Y-m-d', $timestamp );
737
+								$object[$wordpress_field] = date_i18n('Y-m-d', $timestamp);
738 738
 							}
739 739
 						}
740 740
 					}
741 741
 
742 742
 					// Boolean SF fields only want real boolean values. NULL is also not allowed.
743
-					if ( 'boolean' === $salesforce_field_type ) {
744
-						$object[ $wordpress_field ] = (bool) $object[ $wordpress_field ];
743
+					if ('boolean' === $salesforce_field_type) {
744
+						$object[$wordpress_field] = (bool) $object[$wordpress_field];
745 745
 					}
746 746
 				}
747 747
 
748
-				$params[ $salesforce_field ] = $object[ $wordpress_field ];
748
+				$params[$salesforce_field] = $object[$wordpress_field];
749 749
 
750 750
 				// If the field is a key in salesforce, remove it from $params to avoid upsert errors from salesforce,
751 751
 				// but still put its name in the params array so we can check for it later.
752
-				if ( '1' === $fieldmap['is_key'] ) {
753
-					if ( ! $use_soap ) {
754
-						unset( $params[ $salesforce_field ] );
752
+				if ('1' === $fieldmap['is_key']) {
753
+					if ( ! $use_soap) {
754
+						unset($params[$salesforce_field]);
755 755
 					}
756 756
 					$params['key'] = array(
757 757
 						'salesforce_field' => $salesforce_field,
758 758
 						'wordpress_field'  => $wordpress_field,
759
-						'value'            => $object[ $wordpress_field ],
759
+						'value'            => $object[$wordpress_field],
760 760
 					);
761 761
 				}
762 762
 
763 763
 				// If the field is a prematch in salesforce, put its name in the params array so we can check for it later.
764
-				if ( '1' === $fieldmap['is_prematch'] ) {
764
+				if ('1' === $fieldmap['is_prematch']) {
765 765
 					$params['prematch'] = array(
766 766
 						'salesforce_field' => $salesforce_field,
767 767
 						'wordpress_field'  => $wordpress_field,
768
-						'value'            => $object[ $wordpress_field ],
768
+						'value'            => $object[$wordpress_field],
769 769
 					);
770 770
 				}
771 771
 
772 772
 				// I think it's good to over-mention that updateable is really how the Salesforce api spells it.
773 773
 				// Skip fields that aren't updateable when mapping params because Salesforce will error otherwise.
774 774
 				// This happens after dealing with the field types because key and prematch should still be available to the plugin, even if the values are not updateable in Salesforce.
775
-				if ( 1 !== (int) $fieldmap['salesforce_field']['updateable'] ) {
776
-					unset( $params[ $salesforce_field ] );
775
+				if (1 !== (int) $fieldmap['salesforce_field']['updateable']) {
776
+					unset($params[$salesforce_field]);
777 777
 				}
778
-			} elseif ( in_array( $trigger, $salesforce_haystack, true ) ) {
778
+			} elseif (in_array($trigger, $salesforce_haystack, true)) {
779 779
 
780 780
 				// A salesforce event caused this.
781 781
 
782
-				if ( isset( $salesforce_field_type ) ) {
782
+				if (isset($salesforce_field_type)) {
783 783
 					// Salesforce provides multipicklist values as a delimited string. If the
784 784
 					// destination field in WordPress accepts multiple values, explode the string
785 785
 					// into an array and then serialize it.
786
-					if ( in_array( $salesforce_field_type, $this->array_types_from_salesforce ) ) {
787
-						$object[ $salesforce_field ] = explode( $this->array_delimiter, $object[ $salesforce_field ] );
786
+					if (in_array($salesforce_field_type, $this->array_types_from_salesforce)) {
787
+						$object[$salesforce_field] = explode($this->array_delimiter, $object[$salesforce_field]);
788 788
 					}
789 789
 
790 790
 					// Handle specific data types from Salesforce.
791
-					switch ( $salesforce_field_type ) {
792
-						case ( in_array( $salesforce_field_type, $this->date_types_from_salesforce ) ):
793
-							$format = get_option( 'date_format', 'U' );
794
-							if ( isset( $fieldmap['wordpress_field']['type'] ) && 'datetime' === $fieldmap['wordpress_field']['type'] ) {
791
+					switch ($salesforce_field_type) {
792
+						case (in_array($salesforce_field_type, $this->date_types_from_salesforce)):
793
+							$format = get_option('date_format', 'U');
794
+							if (isset($fieldmap['wordpress_field']['type']) && 'datetime' === $fieldmap['wordpress_field']['type']) {
795 795
 								$format = 'Y-m-d H:i:s';
796 796
 							}
797
-							$object[ $salesforce_field ] = date_i18n( $format, strtotime( $object[ $salesforce_field ] ) );
797
+							$object[$salesforce_field] = date_i18n($format, strtotime($object[$salesforce_field]));
798 798
 							break;
799
-						case ( in_array( $salesforce_field_type, $this->int_types_from_salesforce ) ):
800
-							$object[ $salesforce_field ] = isset( $object[ $salesforce_field ] ) ? (int) $object[ $salesforce_field ] : 0;
799
+						case (in_array($salesforce_field_type, $this->int_types_from_salesforce)):
800
+							$object[$salesforce_field] = isset($object[$salesforce_field]) ? (int) $object[$salesforce_field] : 0;
801 801
 							break;
802 802
 						case 'text':
803
-							$object[ $salesforce_field ] = (string) $object[ $salesforce_field ];
803
+							$object[$salesforce_field] = (string) $object[$salesforce_field];
804 804
 							break;
805 805
 						case 'url':
806
-							$object[ $salesforce_field ] = esc_url_raw( $object[ $salesforce_field ] );
806
+							$object[$salesforce_field] = esc_url_raw($object[$salesforce_field]);
807 807
 							break;
808 808
 					}
809 809
 				}
810 810
 
811 811
 				// Make an array because we need to store the methods for each field as well.
812
-				$params[ $wordpress_field ]          = array();
813
-				$params[ $wordpress_field ]['value'] = $object[ $salesforce_field ];
812
+				$params[$wordpress_field]          = array();
813
+				$params[$wordpress_field]['value'] = $object[$salesforce_field];
814 814
 
815 815
 				// If the field is a key in salesforce, remove it from $params to avoid upsert errors from salesforce,
816 816
 				// but still put its name in the params array so we can check for it later.
817
-				if ( '1' === $fieldmap['is_key'] ) {
818
-					if ( ! $use_soap ) {
819
-						unset( $params[ $wordpress_field ] );
817
+				if ('1' === $fieldmap['is_key']) {
818
+					if ( ! $use_soap) {
819
+						unset($params[$wordpress_field]);
820 820
 					}
821 821
 					$params['key'] = array(
822 822
 						'salesforce_field' => $salesforce_field,
823 823
 						'wordpress_field'  => $wordpress_field,
824
-						'value'            => $object[ $salesforce_field ],
824
+						'value'            => $object[$salesforce_field],
825 825
 						'method_read'      => $fieldmap['wordpress_field']['methods']['read'],
826 826
 						'method_create'    => $fieldmap['wordpress_field']['methods']['create'],
827 827
 						'method_update'    => $fieldmap['wordpress_field']['methods']['update'],
@@ -829,30 +829,30 @@  discard block
 block discarded – undo
829 829
 				}
830 830
 
831 831
 				// If the field is a prematch in salesforce, put its name in the params array so we can check for it later.
832
-				if ( '1' === $fieldmap['is_prematch'] ) {
832
+				if ('1' === $fieldmap['is_prematch']) {
833 833
 					$params['prematch'] = array(
834 834
 						'salesforce_field' => $salesforce_field,
835 835
 						'wordpress_field'  => $wordpress_field,
836
-						'value'            => $object[ $salesforce_field ],
836
+						'value'            => $object[$salesforce_field],
837 837
 						'method_read'      => $fieldmap['wordpress_field']['methods']['read'],
838 838
 						'method_create'    => $fieldmap['wordpress_field']['methods']['create'],
839 839
 						'method_update'    => $fieldmap['wordpress_field']['methods']['update'],
840 840
 					);
841 841
 				}
842 842
 
843
-				switch ( $trigger ) {
843
+				switch ($trigger) {
844 844
 					case $this->sync_sf_create:
845
-						$params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['create'];
845
+						$params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['create'];
846 846
 						break;
847 847
 					case $this->sync_sf_update:
848
-						$params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['update'];
848
+						$params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['update'];
849 849
 						break;
850 850
 					case $this->sync_sf_delete:
851
-						$params[ $wordpress_field ]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete'];
851
+						$params[$wordpress_field]['method_modify'] = $fieldmap['wordpress_field']['methods']['delete'];
852 852
 						break;
853 853
 				}
854 854
 
855
-				$params[ $wordpress_field ]['method_read'] = $fieldmap['wordpress_field']['methods']['read'];
855
+				$params[$wordpress_field]['method_read'] = $fieldmap['wordpress_field']['methods']['read'];
856 856
 
857 857
 			} // End if().
858 858
 		} // End foreach().
@@ -869,14 +869,14 @@  discard block
 block discarded – undo
869 869
 	 *
870 870
 	 * @return array $mappings Associative array of field maps ready to use
871 871
 	 */
872
-	private function prepare_fieldmap_data( $mappings, $record_type = '' ) {
873
-
874
-		foreach ( $mappings as $id => $mapping ) {
875
-			$mappings[ $id ]['salesforce_record_types_allowed'] = maybe_unserialize( $mapping['salesforce_record_types_allowed'] );
876
-			$mappings[ $id ]['fields']                          = maybe_unserialize( $mapping['fields'] );
877
-			$mappings[ $id ]['sync_triggers']                   = maybe_unserialize( $mapping['sync_triggers'] );
878
-			if ( '' !== $record_type && ! in_array( $record_type, $mappings[ $id ]['salesforce_record_types_allowed'], true ) ) {
879
-				unset( $mappings[ $id ] );
872
+	private function prepare_fieldmap_data($mappings, $record_type = '') {
873
+
874
+		foreach ($mappings as $id => $mapping) {
875
+			$mappings[$id]['salesforce_record_types_allowed'] = maybe_unserialize($mapping['salesforce_record_types_allowed']);
876
+			$mappings[$id]['fields']                          = maybe_unserialize($mapping['fields']);
877
+			$mappings[$id]['sync_triggers']                   = maybe_unserialize($mapping['sync_triggers']);
878
+			if ('' !== $record_type && ! in_array($record_type, $mappings[$id]['salesforce_record_types_allowed'], true)) {
879
+				unset($mappings[$id]);
880 880
 			}
881 881
 		}
882 882
 
@@ -892,12 +892,12 @@  discard block
 block discarded – undo
892 892
 	public function get_failed_object_maps() {
893 893
 		$table       = $this->object_map_table;
894 894
 		$errors      = array();
895
-		$push_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A );
896
-		$pull_errors = $this->wpdb->get_results( 'SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A );
897
-		if ( ! empty( $push_errors ) ) {
895
+		$push_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE salesforce_id LIKE "tmp_sf_%"', ARRAY_A);
896
+		$pull_errors = $this->wpdb->get_results('SELECT * FROM ' . $table . ' WHERE wordpress_id LIKE "tmp_wp_%"', ARRAY_A);
897
+		if ( ! empty($push_errors)) {
898 898
 			$errors['push_errors'] = $push_errors;
899 899
 		}
900
-		if ( ! empty( $pull_errors ) ) {
900
+		if ( ! empty($pull_errors)) {
901 901
 			$errors['pull_errors'] = $pull_errors;
902 902
 		}
903 903
 		return $errors;
@@ -910,11 +910,11 @@  discard block
 block discarded – undo
910 910
 	 *
911 911
 	 * @return array $error Associative array of single row that failed to finish based on id
912 912
 	 */
913
-	public function get_failed_object_map( $id ) {
913
+	public function get_failed_object_map($id) {
914 914
 		$table     = $this->object_map_table;
915 915
 		$error     = array();
916
-		$error_row = $this->wpdb->get_row( 'SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A );
917
-		if ( ! empty( $error_row ) ) {
916
+		$error_row = $this->wpdb->get_row('SELECT * FROM ' . $table . ' WHERE id = "' . $id . '"', ARRAY_A);
917
+		if ( ! empty($error_row)) {
918 918
 			$error = $error_row;
919 919
 		}
920 920
 		return $error;
Please login to merge, or discard this patch.