ZillowPastSalesWidget::update()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 4
nop 2
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 17 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/* Exit if accessed directly. */
4
if ( ! defined( 'ABSPATH' ) ) { exit; }
5
6
/**
7
 * Zillow Past Sales Widget (https://www.zillow.com/webtools/widgets/PastListingsWidget.htm)
8
 *
9
 * @package RE-PRO
10
 */
11
12
/**
13
 * ZillowPastSalesWidget class.
14
 *
15
 * @extends WP_Widget
16
 */
17
class ZillowPastSalesWidget extends WP_Widget {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
18
19
20
	/**
21
	 * __construct function.
22
	 *
23
	 * @access public
24
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
25
	 */
26
	public function __construct() {
27
28
		parent::__construct(
29
			'zillow_past_sales_widget',
30
			__( 'Zillow Past Sales', 're-pro' ),
31
			array(
32
				'description' => __( 'Display your past sales from Zillow.', 're-pro' ),
33
				'classname'   => 're-pro re-pro-widget zillow-widget zillow-widget-past-sales',
34
				'customize_selective_refresh' => true,
35
			)
36
		);
37
	}
38
39
	/**
40
	 * Widget function.
41
	 *
42
	 * @access public
43
	 * @param mixed $args Arguments.
44
	 * @param mixed $instance Instance.
45
	 * @return void
46
	 */
47 View Code Duplication
	public function widget( $args, $instance ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
49
		$iframe_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : '';
50
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
51
		$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : '';
52
53
54
		echo $args['before_widget'];
55
56
		echo $args['before_title'] . esc_attr( $title ) . $args['after_title'];
57
58
		$zillow_widgets = new ZillowWidgets();
59
60
		return $zillow_widgets->get_past_listings_widget( $iframe_id, $zuid );
61
62
		echo $args['after_widget'];
0 ignored issues
show
Unused Code introduced by
echo $args['after_widget']; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
63
	}
64
65
	/**
66
	 * Form function.
67
	 *
68
	 * @access public
69
	 * @param mixed $instance Instance.
70
	 * @return void
71
	 */
72
	public function form( $instance ) {
73
74
		// Set default values.
75
		$instance = wp_parse_args( (array) $instance, array(
76
			'title' => '',
77
			'zuid' => '',
78
		));
79
80
		// Retrieve an existing value from the database.
81
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
82
		$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : '';
0 ignored issues
show
Unused Code introduced by
$screenname is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
83
		$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : '';
84
		$format = ! empty( $instance['format'] ) ? $instance['format'] : 'format';
0 ignored issues
show
Unused Code introduced by
$format is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
85
86
		// Title.
87
		echo '<p>';
88
		echo '	<label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>';
89
		echo '	<input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title  . '" class="widefat">';
90
		echo '</p>';
91
92
		// Zillow User ID.
93
		echo '<p>';
94
		echo '	<label for="' . $this->get_field_id( 'zuid' ) . '" class="title-label">' . __( 'Zillow User ID:', 're-pro' ) . '</label>';
95
		echo '	<input id="' . $this->get_field_id( 'zuid' ) . '" name="' . $this->get_field_name( 'zuid' ) . '" value="' . $zuid  . '" class="widefat">';
96
		echo '</p>';
97
98
	}
99
100
	/**
101
	 * Update.
102
	 *
103
	 * @access public
104
	 * @param mixed $new_instance New Instance.
105
	 * @param mixed $old_instance Old Instance.
106
	 * @return $instance
0 ignored issues
show
Documentation introduced by
The doc-type $instance could not be parsed: Unknown type name "$instance" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
107
	 */
108
	public function update( $new_instance, $old_instance ) {
109
110
		$instance = $old_instance;
111
112
		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
113
		$instance['zuid'] = ! empty( $new_instance['zuid'] ) ? strip_tags( $new_instance['zuid'] ) : '';
114
115
		return $instance;
116
	}
117
}
118
119
/**
120
 * Register Zillow Review Widget.
121
 *
122
 * @access public
123
 * @return void
124
 */
125
/*function repro_zillow_past_sales_widget() {
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126
127
	register_widget( 'ZillowPastSalesWidget' );
128
}
129
add_action( 'widgets_init', 'repro_zillow_past_sales_widget' );*/
130