LSX_WC_Widget_Recent_Reviews::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 17
nc 1
nop 0
dl 0
loc 22
rs 9.7
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7
/**
8
 * Recent Reviews Widget.
9
 *
10
 * @author   WooThemes
11
 * @category Widgets
12
 * @package  WooCommerce/Widgets
13
 * @version  2.3.0
14
 * @extends  WC_Widget
15
 */
16
class LSX_WC_Widget_Recent_Reviews extends WC_Widget {
0 ignored issues
show
Bug introduced by
The type WC_Widget was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
	/**
19
	 * Constructor.
20
	 */
21
	public function __construct() {
22
		$this->widget_cssclass    = 'woocommerce widget_recent_reviews';
0 ignored issues
show
Bug Best Practice introduced by
The property widget_cssclass does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
		$this->widget_description = __( 'Display a list of your most recent reviews on your site.', 'lsx' );
0 ignored issues
show
Bug Best Practice introduced by
The property widget_description does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
		$this->widget_id          = 'woocommerce_recent_reviews';
0 ignored issues
show
Bug Best Practice introduced by
The property widget_id does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
25
		$this->widget_name        = __( 'WooCommerce recent reviews', 'lsx' );
0 ignored issues
show
Bug Best Practice introduced by
The property widget_name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
		$this->settings           = array(
0 ignored issues
show
Bug Best Practice introduced by
The property settings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
			'title'  => array(
28
				'type'  => 'text',
29
				'std'   => __( 'Recent reviews', 'lsx' ),
30
				'label' => __( 'Title', 'lsx' ),
31
			),
32
			'number' => array(
33
				'type'  => 'number',
34
				'step'  => 1,
35
				'min'   => 1,
36
				'max'   => '',
37
				'std'   => 10,
38
				'label' => __( 'Number of reviews to show', 'lsx' ),
39
			),
40
		);
41
42
		parent::__construct();
43
	}
44
45
	/**
46
	 * Output widget.
47
	 *
48
	 * @see WP_Widget
49
	 *
50
	 * @param array $args
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
51
	 * @param array $instance
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
52
	 */
53
	public function widget( $args, $instance ) {
54
		if ( $this->get_cached_widget( $args ) ) {
55
			return;
56
		}
57
		ob_start();
58
		$number   = ! empty( $instance['number'] ) ? absint( $instance['number'] ) : $this->settings['number']['std'];
59
		$comments = get_comments(
60
			array(
61
				'number'      => $number,
62
				'status'      => 'approve',
63
				'post_status' => 'publish',
64
				'post_type'   => 'product',
65
				'parent'      => 0,
66
			)
67
		);
68
69
		if ( $comments ) {
70
			$this->widget_start( $args, $instance );
71
72
			echo wp_kses_post( apply_filters( 'woocommerce_before_widget_product_list', '<ul class="product_list_widget">' ) );
73
74
			global $stored_comment, $_product, $rating;
75
76
			the_comment();
77
			foreach ( (array) $comments as $comment ) {
78
				$_product = wc_get_product( $comment->comment_post_ID );
0 ignored issues
show
Bug introduced by
The function wc_get_product was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

78
				$_product = /** @scrutinizer ignore-call */ wc_get_product( $comment->comment_post_ID );
Loading history...
79
				$rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) );
80
				$stored_comment = $comment;
81
82
				wc_get_template( 'content-widget-review.php' );
0 ignored issues
show
Bug introduced by
The function wc_get_template was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

82
				/** @scrutinizer ignore-call */ 
83
    wc_get_template( 'content-widget-review.php' );
Loading history...
83
			}
84
85
			echo wp_kses_post( apply_filters( 'woocommerce_after_widget_product_list', '</ul>' ) );
86
87
			$this->widget_end( $args );
88
		}
89
		$content = ob_get_clean();
90
		echo wp_kses_post( $content );
91
		$this->cache_widget( $args, $content );
92
	}
93
}
94