Automattic /
jetpack
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
|
|||
| 33 | return ''; |
||
| 34 | } |
||
| 35 | |||
| 36 | $variation_data = $product->is_type( 'variation' ) ? wc_get_product_variation_attributes( $product->get_id() ) : ''; |
||
|
0 ignored issues
–
show
|
|||
| 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
|
|||
| 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 |
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.