Passed
Push — 196-autoloading ( a3379e )
by Jonathan
07:18
created

Object_Sync_Salesforce::composer_loaded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * The main plugin class
4
 *
5
 * @class   Object_Sync_Salesforce
6
 * @package Object_Sync_Salesforce
7
 */
8
9
defined( 'ABSPATH' ) || exit;
10
11
/**
12
 * Object_Sync_Salesforce class.
13
 */
14
class Object_Sync_Salesforce {
15
16
	/**
17
	 * Current version of the plugin
18
	 *
19
	 * @var string
20
	 */
21
	public $version;
22
23
	/**
24
	 * The main plugin file
25
	 *
26
	 * @var string
27
	 */
28
	public $file;
29
30
	/**
31
	 * Global object of `$wpdb`, the WordPress database
32
	 *
33
	 * @var object
34
	 */
35
	public $wpdb;
36
37
	/**
38
	 * The plugin's slug so we can include it when necessary
39
	 *
40
	 * @var string
41
	 */
42
	public $slug;
43
44
	/**
45
	 * The plugin's prefix when saving options to the database
46
	 *
47
	 * @var string
48
	 */
49
	public $option_prefix;
50
51
	/**
52
	 * Login credentials for the Salesforce API; comes from wp-config or from the plugin settings
53
	 *
54
	 * @var array
55
	 */
56
	public $login_credentials;
57
58
	/**
59
	 * Array of what classes in the plugin can be scheduled to occur with `wp_cron` events
60
	 *
61
	 * @var array
62
	 */
63
	public $schedulable_classes;
64
65
	/**
66
	 * Array of what classes in the plugin can be scheduled to occur with `wp_cron` events
67
	 *
68
	 * @var array
69
	 */
70
	public $queue;
71
72
	/**
73
	 * Tells us if composer has been autoloaded
74
	 *
75
	 * @var bool
76
	 */
77
	private $composer_loaded;
78
79
	/**
80
	 * Object_Sync_Sf_Activate class
81
	 *
82
	 * @var object
83
	 */
84
	private $activated;
85
86
	/**
87
	 * Object_Sync_Sf_Logging class
88
	 *
89
	 * @var object
90
	 */
91
	public $logging;
92
93
	/**
94
	 * Object_Sync_Sf_Mapping class
95
	 *
96
	 * @var object
97
	 */
98
	public $mappings;
99
100
	/**
101
	 * Object_Sync_Sf_WordPress class
102
	 *
103
	 * @var object
104
	 */
105
	public $wordpress;
106
107
	/**
108
	 * Object_Sync_Sf_Salesforce class
109
	 * This contains Salesforce API methods
110
	 *
111
	 * @var array
112
	 */
113
	public $salesforce;
114
115
	/**
116
	 * Object_Sync_Sf_Salesforce_Push class
117
	 *
118
	 * @var object
119
	 */
120
	public $push;
121
122
	/**
123
	 * Object_Sync_Sf_Salesforce_Pull class
124
	 *
125
	 * @var object
126
	 */
127
	public $pull;
128
129
	/**
130
	 * Object_Sync_Sf_Rest class
131
	 *
132
	 * @var object
133
	 */
134
	private $rest;
135
136
	/**
137
	 * Legacy property that holds an instance of the plugin class.
138
	 *
139
	 * @var object
140
	 * @deprecated since 2.0.0
141
	 */
142
	public static $instance;
143
144
	/**
145
	 * This is our constructor
146
	 *
147
	 * @param string $version is the plugin version.
148
	 * @param string $file is the main plugin file.
149
	 * @return void
150
	 */
151
	public function __construct( $version, $file ) {
152
153
		global $wpdb;
154
155
		$this->version       = $version;
156
		$this->file          = $file;
157
		$this->wpdb          = $wpdb;
158
		$this->slug          = 'object-sync-for-salesforce';
159
		$this->option_prefix = 'object_sync_for_salesforce_';
160
161
		$this->schedulable_classes = array(
162
			'salesforce_push' => array(
163
				'label'    => 'Push to Salesforce',
164
				'class'    => 'Object_Sync_Sf_Salesforce_Push',
165
				'callback' => $this->option_prefix . 'push_record',
166
			),
167
			'salesforce_pull' => array(
168
				'label'       => 'Pull from Salesforce',
169
				'class'       => 'Object_Sync_Sf_Salesforce_Pull',
170
				'initializer' => $this->option_prefix . 'pull_check_records',
171
				'callback'    => $this->option_prefix . 'pull_process_records',
172
			),
173
		);
174
175
		// users can modify the list of schedulable classes.
176
		$this->schedulable_classes = apply_filters( $this->option_prefix . 'modify_schedulable_classes', $this->schedulable_classes );
177
178
		/* // phpcs:ignore Squiz.PHP.CommentedOutCode.Found
179
		 * example to modify the array of classes by adding one and removing one
180
		 * add_filter( 'object_sync_for_salesforce_modify_schedulable_classes', 'modify_schedulable_classes', 10, 1 );
181
		 * function modify_schedulable_classes( $schedulable_classes ) {
182
		 * 	$schedulable_classes = array(
183
		 * 		'salesforce_push' => array(
184
		 * 		    'label' => 'Push to Salesforce',
185
		 * 		    'class' => 'Object_Sync_Sf_Salesforce_Push',
186
		 * 		    'callback' => 'salesforce_push_sync_rest',
187
		 * 		),
188
		 * 		'wordpress' => array( // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled
189
		 * 		    'label' => 'WordPress',
190
		 * 		    'class' => 'Object_Sync_Sf_WordPress',
191
		 * 		),
192
		 * 		'salesforce' => array(
193
		 * 		    'label' => 'Salesforce Authorization',
194
		 * 		    'class' => 'Object_Sync_Sf_Salesforce',
195
		 * 		),
196
		 * 	);
197
		 * 	return $schedulable_classes;
198
		 * }
199
		*/
200
	}
201
202
	/**
203
	 * Load the static $instance property that holds the instance of the class.
204
	 * This is preserved for legacy usage, as the same thing exists in the `object_sync_for_salesforce` function.
205
	 *
206
	 * @return object $plugin
207
	 * @deprecated since 2.0.0
208
	 */
209
	public static function get_instance() {
210
211
		if ( function_exists( 'object_sync_for_salesforce' ) ) {
212
			return object_sync_for_salesforce();
213
		}
214
215
		static $plugin;
216
217
		if ( is_null( $plugin ) ) {
218
			$plugin = new Object_Sync_Salesforce( OBJECT_SYNC_SALESFORCE_VERSION, OBJECT_SYNC_SALESFORCE_FILE );
219
		}
220
221
		return $plugin;
222
	}
223
224
	/**
225
	 * Initialize the plugin and start the action hooks.
226
	 * We run this separately because activate can't run without the right priority.
227
	 */
228
	public function init() {
229
		$this->activated = $this->activate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::activate() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

229
		/** @scrutinizer ignore-call */ 
230
  $this->activated = $this->activate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
230
		$this->add_actions();
231
	}
232
233
	/**
234
	 * What to do upon activation of the plugin
235
	 *
236
	 * @return object $activate
237
	 */
238
	private function activate() {
239
		$activate = new Object_Sync_Sf_Activate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue );
0 ignored issues
show
Bug introduced by
$this->queue of type array is incompatible with the type object expected by parameter $queue of Object_Sync_Sf_Activate::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

239
		$activate = new Object_Sync_Sf_Activate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, /** @scrutinizer ignore-type */ $this->queue );
Loading history...
240
		return $activate;
241
	}
242
243
	/**
244
	 * Run non-activation actions.
245
	 * We do this on -10 because ActionScheduler has to have access to plugins_loaded with priority of zero.
246
	 */
247
	private function add_actions() {
248
		// public actions.
249
		add_action( 'plugins_loaded', array( $this, 'run' ), -10 );
250
		add_action( 'plugins_loaded', array( $this, 'textdomain' ) );
251
	}
252
253
	/**
254
	 * Run the plugin, independent of activation methods.
255
	 */
256
	public function run() {
257
258
		$this->composer_loaded = $this->composer_loaded();
259
260
		$this->login_credentials = $this->get_login_credentials();
261
262
		$this->deactivate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::deactivate() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

262
		$this->/** @scrutinizer ignore-call */ 
263
         deactivate( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes, $this->queue );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
263
264
		$this->logging = $this->logging( $this->wpdb, $this->version, $this->slug, $this->option_prefix );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::logging() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

264
		/** @scrutinizer ignore-call */ 
265
  $this->logging = $this->logging( $this->wpdb, $this->version, $this->slug, $this->option_prefix );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
265
266
		$this->queue = $this->queue( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes );
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->queue($this->wpdb...s->schedulable_classes) of type Object_Sync_Sf_Queue is incompatible with the declared type array of property $queue.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
Unused Code introduced by
The call to Object_Sync_Salesforce::queue() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

266
		/** @scrutinizer ignore-call */ 
267
  $this->queue = $this->queue( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
267
268
		$this->mappings = $this->mappings( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->logging );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::mappings() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

268
		/** @scrutinizer ignore-call */ 
269
  $this->mappings = $this->mappings( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->logging );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
269
270
		$this->wordpress  = $this->wordpress( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->mappings, $this->logging );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::wordpress() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

270
		/** @scrutinizer ignore-call */ 
271
  $this->wordpress  = $this->wordpress( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->mappings, $this->logging );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
271
		$this->salesforce = $this->salesforce_get_api();
272
273
		$this->push = $this->push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::push() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

273
		/** @scrutinizer ignore-call */ 
274
  $this->push = $this->push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
274
275
		$this->pull = $this->pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::pull() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

275
		/** @scrutinizer ignore-call */ 
276
  $this->pull = $this->pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
276
277
		$this->rest = $this->rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull );
0 ignored issues
show
Unused Code introduced by
The call to Object_Sync_Salesforce::rest() has too many arguments starting with $this->wpdb. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

277
		/** @scrutinizer ignore-call */ 
278
  $this->rest = $this->rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
278
279
		new Object_Sync_Sf_Admin();
280
	}
281
282
	/**
283
	 * Autoload things from Composer.
284
	 *
285
	 * @return bool true
286
	 */
287
	private function composer_loaded() {
288
		require_once plugin_dir_path( $this->file ) . 'vendor/autoload.php';
289
		return true;
290
	}
291
292
	/**
293
	 * Get the pre-login Salesforce credentials.
294
	 * These depend on the plugin's settings or constants defined in wp-config.php.
295
	 *
296
	 * @return array $login_credentials
297
	 */
298
	private function get_login_credentials() {
299
300
		$consumer_key       = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY : get_option( $this->option_prefix . 'consumer_key', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_CONSUMER_KEY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
301
		$consumer_secret    = defined( 'OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET' ) ? OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET : get_option( $this->option_prefix . 'consumer_secret', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_CONSUMER_SECRET was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
302
		$callback_url       = defined( 'OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL : get_option( $this->option_prefix . 'callback_url', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_CALLBACK_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
303
		$login_base_url     = defined( 'OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL' ) ? OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL : get_option( $this->option_prefix . 'login_base_url', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_LOGIN_BASE_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
304
		$authorize_url_path = defined( 'OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH' ) ? OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH : get_option( $this->option_prefix . 'authorize_url_path', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_AUTHORIZE_URL_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
305
		$token_url_path     = defined( 'OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH' ) ? OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH : get_option( $this->option_prefix . 'token_url_path', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_TOKEN_URL_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
306
		$api_version        = defined( 'OBJECT_SYNC_SF_SALESFORCE_API_VERSION' ) ? OBJECT_SYNC_SF_SALESFORCE_API_VERSION : get_option( $this->option_prefix . 'api_version', '' );
0 ignored issues
show
Bug introduced by
The constant OBJECT_SYNC_SF_SALESFORCE_API_VERSION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
307
308
		$login_credentials = array(
309
			'consumer_key'     => $consumer_key,
310
			'consumer_secret'  => $consumer_secret,
311
			'callback_url'     => $callback_url,
312
			'login_url'        => $login_base_url,
313
			'authorize_path'   => $authorize_url_path,
314
			'token_path'       => $token_url_path,
315
			'rest_api_version' => $api_version,
316
		);
317
318
		return $login_credentials;
319
320
	}
321
322
	/**
323
	 * What to do upon deactivation of the plugin
324
	 */
325
	private function deactivate() {
326
		$deactivate = new Object_Sync_Sf_Deactivate( $this->wpdb, $this->version, $this->slug, $this->schedulable_classes, $this->option_prefix, $this->queue );
0 ignored issues
show
Bug introduced by
$this->queue of type array is incompatible with the type object expected by parameter $queue of Object_Sync_Sf_Deactivate::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

326
		$deactivate = new Object_Sync_Sf_Deactivate( $this->wpdb, $this->version, $this->slug, $this->schedulable_classes, $this->option_prefix, /** @scrutinizer ignore-type */ $this->queue );
Loading history...
327
	}
328
329
	/**
330
	 * Log plugin events
331
	 *
332
	 * @return object $logging
333
	 */
334
	private function logging() {
335
		$logging = new Object_Sync_Sf_Logging( $this->wpdb, $this->version, $this->slug, $this->option_prefix );
336
		return $logging;
337
	}
338
339
	/**
340
	 * Get queue instance
341
	 *
342
	 * @return object $queue
343
	 */
344
	public function queue() {
345
		$queue = new Object_Sync_Sf_Queue( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->schedulable_classes );
346
		return $queue;
347
	}
348
349
	/**
350
	 * Map the Salesforce and WordPress objects and fields to each other
351
	 *
352
	 * @return object $mappings
353
	 */
354
	public function mappings() {
355
		$mappings = new Object_Sync_Sf_Mapping( $this->wpdb, $this->version, $this->slug, $this->logging, $this->option_prefix );
356
		return $mappings;
357
	}
358
359
	/**
360
	 * Load methods for manipulating core WordPress data across the plugin
361
	 *
362
	 * @return object $wordpress
363
	 */
364
	public function wordpress() {
365
		$wordpress = new Object_Sync_Sf_WordPress( $this->wpdb, $this->version, $this->slug, $this->mappings, $this->logging, $this->option_prefix );
366
		return $wordpress;
367
	}
368
369
	/**
370
	 * Public helper to load the Salesforce API and see if it is authenticated.
371
	 * This is public so other plugins can access the same SF API instance we use.
372
	 *
373
	 * @return array
374
	 */
375
	public function salesforce_get_api() {
376
377
		$soap_available = $this->is_soap_available();
378
		$soap_loaded    = $this->is_soap_loaded();
379
380
		$consumer_key        = $this->login_credentials['consumer_key'];
381
		$consumer_secret     = $this->login_credentials['consumer_secret'];
382
		$login_url           = $this->login_credentials['login_url'];
383
		$callback_url        = $this->login_credentials['callback_url'];
384
		$authorize_path      = $this->login_credentials['authorize_path'];
385
		$token_path          = $this->login_credentials['token_path'];
386
		$rest_api_version    = $this->login_credentials['rest_api_version'];
387
		$slug                = $this->slug;
388
		$option_prefix       = $this->option_prefix;
389
		$wordpress           = $this->wordpress;
390
		$logging             = $this->logging;
391
		$schedulable_classes = $this->schedulable_classes;
392
		$is_authorized       = false;
393
		$sfapi               = '';
394
		if ( $consumer_key && $consumer_secret ) {
395
			$sfapi = new Object_Sync_Sf_Salesforce( $consumer_key, $consumer_secret, $login_url, $callback_url, $authorize_path, $token_path, $rest_api_version, $wordpress, $slug, $logging, $schedulable_classes, $option_prefix );
396
			if ( true === $sfapi->is_authorized() ) {
397
				$is_authorized = true;
398
			}
399
		}
400
401
		return array(
402
			'is_authorized'  => $is_authorized,
403
			'sfapi'          => $sfapi,
404
			'soap_available' => $soap_available,
405
			'soap_loaded'    => $soap_loaded,
406
		);
407
	}
408
409
	/**
410
	 * Methods to push data from WordPress to Salesforce
411
	 *
412
	 * @return object $push
413
	 */
414
	public function push() {
415
		$push = new Object_Sync_Sf_Salesforce_Push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue, $this->option_prefix );
0 ignored issues
show
Bug introduced by
$this->queue of type array is incompatible with the type object expected by parameter $queue of Object_Sync_Sf_Salesforce_Push::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

415
		$push = new Object_Sync_Sf_Salesforce_Push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, /** @scrutinizer ignore-type */ $this->queue, $this->option_prefix );
Loading history...
Bug introduced by
$this->salesforce of type array is incompatible with the type object expected by parameter $salesforce of Object_Sync_Sf_Salesforce_Push::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

415
		$push = new Object_Sync_Sf_Salesforce_Push( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue, $this->option_prefix );
Loading history...
416
		return $push;
417
	}
418
419
	/**
420
	 * Methods to pull data from Salesforce to WordPress
421
	 *
422
	 * @return object $pull
423
	 */
424
	public function pull() {
425
		$pull = new Object_Sync_Sf_Salesforce_Pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue, $this->option_prefix );
0 ignored issues
show
Bug introduced by
$this->queue of type array is incompatible with the type object expected by parameter $queue of Object_Sync_Sf_Salesforce_Pull::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

425
		$pull = new Object_Sync_Sf_Salesforce_Pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, /** @scrutinizer ignore-type */ $this->queue, $this->option_prefix );
Loading history...
Bug introduced by
$this->salesforce of type array is incompatible with the type object expected by parameter $salesforce of Object_Sync_Sf_Salesforce_Pull::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

425
		$pull = new Object_Sync_Sf_Salesforce_Pull( $this->wpdb, $this->version, $this->login_credentials, $this->slug, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->logging, $this->schedulable_classes, $this->queue, $this->option_prefix );
Loading history...
426
		return $pull;
427
	}
428
429
	/**
430
	 * REST API methods
431
	 *
432
	 * @return object $rest
433
	 */
434
	private function rest() {
435
		$rest = new Object_Sync_Sf_Rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, $this->salesforce, $this->mappings, $this->push, $this->pull );
0 ignored issues
show
Bug introduced by
$this->salesforce of type array is incompatible with the type object expected by parameter $salesforce of Object_Sync_Sf_Rest::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

435
		$rest = new Object_Sync_Sf_Rest( $this->wpdb, $this->version, $this->slug, $this->option_prefix, $this->wordpress, /** @scrutinizer ignore-type */ $this->salesforce, $this->mappings, $this->push, $this->pull );
Loading history...
436
		return $rest;
437
	}
438
439
	/**
440
	 * Load textdomain
441
	 */
442
	public function textdomain() {
443
		load_plugin_textdomain( 'object-sync-for-salesforce', false, dirname( plugin_basename( $this->file ) ) . '/languages/' );
444
	}
445
446
	/**
447
	 * Check the server to see if Soap is available
448
	 *
449
	 * @return bool $is_soap_available
450
	 */
451
	private function is_soap_available() {
452
		$is_soap_available = false;
453
		if ( extension_loaded( 'soap' ) && class_exists( 'SoapClient' ) ) {
454
			$is_soap_available = true;
455
		}
456
		return $is_soap_available;
457
	}
458
459
	/**
460
	 * Check the plugin to see if the Soap option has been enabled and the class has been loaded
461
	 *
462
	 * @return bool $is_soap_loaded
463
	 */
464
	private function is_soap_loaded() {
465
		$is_soap_loaded = false;
466
		if ( false === $this->is_soap_available() ) {
467
			return $is_soap_loaded;
468
		}
469
		$use_soap = filter_var( get_option( 'object_sync_for_salesforce_use_soap', false ), FILTER_VALIDATE_BOOLEAN );
470
		if ( false === $use_soap ) {
471
			return $is_soap_loaded;
472
		}
473
		if ( class_exists( 'Object_Sync_Sf_Salesforce_Soap_Partner' ) ) {
474
			$is_soap_loaded = true;
475
		}
476
		return $is_soap_loaded;
477
	}
478
479
} // end class
480