Passed
Push — master ( fa0560...6b8bc5 )
by Mike
04:54 queued 31s
created

WooEnvironment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A get_settings() 0 36 5
1
<?php
2
/**
3
 * WC information for status report.
4
 *
5
 * @package WooCommerce/Utilities
6
 */
7
8
namespace WooCommerce\RestApi\Controllers\Version4\Utilities;
9
10
/**
11
 * WooEnvironment class.
12
 */
13
class WooEnvironment {
14
15
	/**
16
	 * Get some setting values for the site that are useful for debugging
17
	 * purposes. For full settings access, use the settings api.
18
	 *
19
	 * @return array
20
	 */
21
	public function get_settings() {
22
		// Get a list of terms used for product/order taxonomies.
23
		$term_response = array();
24
		$terms         = get_terms( 'product_type', array( 'hide_empty' => 0 ) );
25
		foreach ( $terms as $term ) {
26
			$term_response[ $term->slug ] = strtolower( $term->name );
27
		}
28
29
		// Get a list of terms used for product visibility.
30
		$product_visibility_terms = array();
31
		$terms                    = get_terms( 'product_visibility', array( 'hide_empty' => 0 ) );
32
		foreach ( $terms as $term ) {
33
			$product_visibility_terms[ $term->slug ] = strtolower( $term->name );
34
		}
35
36
		// Check if WooCommerce.com account is connected.
37
		$woo_com_connected = 'no';
38
		$helper_options    = get_option( 'woocommerce_helper_data', array() );
39
		if ( array_key_exists( 'auth', $helper_options ) && ! empty( $helper_options['auth'] ) ) {
0 ignored issues
show
Bug introduced by
It seems like $helper_options can also be of type false; however, parameter $search of array_key_exists() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

39
		if ( array_key_exists( 'auth', /** @scrutinizer ignore-type */ $helper_options ) && ! empty( $helper_options['auth'] ) ) {
Loading history...
40
			$woo_com_connected = 'yes';
41
		}
42
43
		// Return array of useful settings for debugging.
44
		return array(
45
			'api_enabled'               => 'yes' === get_option( 'woocommerce_api_enabled' ),
46
			'force_ssl'                 => 'yes' === get_option( 'woocommerce_force_ssl_checkout' ),
47
			'currency'                  => get_woocommerce_currency(),
48
			'currency_symbol'           => get_woocommerce_currency_symbol(),
49
			'currency_position'         => get_option( 'woocommerce_currency_pos' ),
50
			'thousand_separator'        => wc_get_price_thousand_separator(),
51
			'decimal_separator'         => wc_get_price_decimal_separator(),
52
			'number_of_decimals'        => wc_get_price_decimals(),
53
			'geolocation_enabled'       => in_array( get_option( 'woocommerce_default_customer_address' ), array( 'geolocation_ajax', 'geolocation' ) ),
54
			'taxonomies'                => $term_response,
55
			'product_visibility_terms'  => $product_visibility_terms,
56
			'woocommerce_com_connected' => $woo_com_connected,
57
		);
58
	}
59
}
60