Completed
Push — fix/typo-pro-promo ( e5832e...fc698e )
by
unknown
29:20
created

classes/wp-woocommerce-analytics-utils.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Jetpack_WooCommerce_Analytics_Options provides a single interface to module options
4
 *
5
 * @package Jetpack
6
 * @author Automattic
7
 */
8
9
/**
10
 * Bail if accessed directly
11
 */
12
if ( ! defined( 'ABSPATH' ) ) {
13
	exit;
14
}
15
16
/**
17
 * Class Jetpack_WooCommerce_Analytics_Utils
18
 * Utility function for WooCommerce Analytics
19
 */
20
class Jetpack_WooCommerce_Analytics_Utils {
21
	/**
22
	 * Gets product categories or varation attributes as a formatted concatenated string
23
	 *
24
	 * @param array $product WC_Product.
25
	 * @return string
26
	 */
27 View Code Duplication
	public static function get_product_categories_concatenated( $product ) {
28
		if ( ! class_exists( 'WooCommerce' ) ) {
29
			return '';
30
		}
31
32
		if ( ! $product ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $product of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
33
			return '';
34
		}
35
36
		$variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : '';
0 ignored issues
show
The method is_type cannot be called on $product (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
The method get_id cannot be called on $product (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
37
		if ( is_array( $variation_data ) && ! empty( $variation_data ) ) {
38
			$line = wc_get_formatted_variation( $variation_data, true );
39
		} else {
40
			$out        = array();
41
			$categories = get_the_terms( $product->get_id(), 'product_cat' );
0 ignored issues
show
The method get_id cannot be called on $product (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
42
			if ( $categories ) {
43
				foreach ( $categories as $category ) {
44
					$out[] = $category->name;
45
				}
46
			}
47
			$line = join( '/', $out );
48
		}
49
		return $line;
50
	}
51
}
52