Code Duplication    Length = 24-24 lines in 2 locations

modules/google-analytics/classes/wp-google-analytics-utils.php 1 location

@@ 22-45 (lines=24) @@
19
	 * @param WC_Product
20
	 * @return string
21
	 */
22
	public static function get_product_categories_concatenated( $product ) {
23
		if ( ! class_exists( 'WooCommerce' ) ) {
24
			return '';
25
		}
26
27
		if ( ! $product ) {
28
			return '';
29
		}
30
31
		$variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : '';
32
		if ( is_array( $variation_data ) && ! empty( $variation_data ) ) {
33
			$line = wc_get_formatted_variation( $variation_data, true );
34
		} else {
35
			$out = array();
36
			$categories = get_the_terms( $product->get_id(), 'product_cat' );
37
			if ( $categories ) {
38
				foreach ( $categories as $category ) {
39
					$out[] = $category->name;
40
				}
41
			}
42
			$line = join( "/", $out );
43
		}
44
		return $line;
45
	}
46
47
	/**
48
	 * Gets a product's SKU with fallback to just ID. IDs are prepended with a hash symbol.

modules/woocommerce-analytics/classes/wp-woocommerce-analytics-utils.php 1 location

@@ 27-50 (lines=24) @@
24
	 * @param array $product WC_Product.
25
	 * @return string
26
	 */
27
	public static function get_product_categories_concatenated( $product ) {
28
		if ( ! class_exists( 'WooCommerce' ) ) {
29
			return '';
30
		}
31
32
		if ( ! $product ) {
33
			return '';
34
		}
35
36
		$variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : '';
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' );
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