ZillowLargeSearchBox   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 19
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
C widget() 0 21 8
B form() 0 44 5
B update() 0 12 5
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 Large Search Box Widget (http://www.zillow.com/webtools/widgets/ZillowLargeSearchBox.htm)
8
 *
9
 * @package RE-PRO
10
 */
11
12
/**
13
 * ZillowLargeSearchBox class.
14
 *
15
 * @extends WP_Widget
16
 */
17
class ZillowLargeSearchBox 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_large_search_box',
30
			__( 'Zillow Large Search Box', 're-pro' ),
31
			array(
32
				'description' => __( 'Display a Large Search Box from Zillow.', 're-pro' ),
33
				'classname'   => 're-pro re-pro-widget zillow-widget zillow-widget-search-box',
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
	public function widget( $args, $instance ) {
48
49
		$iframe_id = ! empty( $args['widget_id'] ) ? $args['widget_id'] : '';
50
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
51
		$type = ! empty( $instance['type'] ) ? $instance['type'] : '';
0 ignored issues
show
Unused Code introduced by
$type 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...
52
		$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : '';
53
		$location = ! empty( $instance['location'] ) ? $instance['location'] : '';
54
		$home_val_info = ! empty( $instance['home_val_info'] ) ? $instance['home_val_info'] : '';
55
		$home_val_info = ( $home_val_info ) ? 'no' : 'yes';
56
57
58
		echo $args['before_widget'];
59
60
		echo $args['before_title'] . esc_attr( $title ) . $args['after_title'];
61
62
		$zillow_widgets = new ZillowWidgets();
63
64
 		$zillow_widgets->get_lg_zillow_search_widget( $iframe_id, $screenname, 'iframe', $location, $home_val_info );
65
66
		echo $args['after_widget'];
67
	}
68
69
	/**
70
	 * Form function.
71
	 *
72
	 * @access public
73
	 * @param mixed $instance Instance.
74
	 * @return void
75
	 */
76
	public function form( $instance ) {
77
78
		// Set default values.
79
		$instance = wp_parse_args( (array) $instance, array(
80
			'title' => '',
81
			'type' => 'iframe',
82
			'screenname' => '',
83
			'location' => '',
84
			'home_val_info' => 0,
85
		));
86
87
		// Retrieve an existing value from the database.
88
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
89
		$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : '';
90
		$location = ! empty( $instance['location'] ) ? $instance['location'] : '';
91
		$home_val_info = ! empty( $instance['home_val_info'] ) ? $instance['home_val_info'] : 0;
92
93
94
		// Title.
95
		echo '<p>';
96
		echo '	<label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>';
97
		echo '	<input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title  . '" class="widefat">';
98
		echo '</p>';
99
100
		// Zillow Screenname.
101
		echo '<p>';
102
		echo '	<label for="' . $this->get_field_id( 'screenname' ) . '" class="title-label">' . __( 'Zillow Screenname:', 're-pro' ) . '</label>';
103
		echo '	<input id="' . $this->get_field_id( 'screenname' ) . '" name="' . $this->get_field_name( 'screenname' ) . '" value="' . $screenname  . '" class="widefat">';
104
		echo '</p>';
105
106
		// Location.
107
		echo '<p>';
108
		echo '	<label for="' . $this->get_field_id( 'location' ) . '" class="title-label">' . __( 'Location:', 're-pro' ) . '</label>';
109
		echo '	<input id="' . $this->get_field_id( 'location' ) . '" placeholder="El Segundo, CA" name="' . $this->get_field_name( 'location' ) . '" value="' . $location  . '" class="widefat">';
110
		echo '</p>';
111
112
		// Home Value Info
113
		echo '<p>';
114
		echo '<input value="1" type="checkbox"' . checked( esc_attr( $home_val_info ), 1, false ) . 'id="' . esc_attr( $this->get_field_id( 'home_val_info' ) ) . '" name="' . esc_attr( $this->get_field_name( 'home_val_info' ) ) . '" />';
115
		echo '<label for="' . $this->get_field_id( 'home_val_info' ) . '">Hide home value information</label>';
116
		echo '</p>';
117
118
119
	}
120
121
	/**
122
	 * Update.
123
	 *
124
	 * @access public
125
	 * @param mixed $new_instance New Instance.
126
	 * @param mixed $old_instance Old Instance.
127
	 * @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...
128
	 */
129
	public function update( $new_instance, $old_instance ) {
130
131
		$instance = $old_instance;
132
133
		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
134
		$instance['screenname'] = ! empty( $new_instance['screenname'] ) ? strip_tags( $new_instance['screenname'] ) : '';
135
		$instance['location'] = ! empty( $new_instance['location'] ) ? strip_tags( $new_instance['location'] ) : '';
136
		$instance['home_val_info'] = ! empty( $new_instance['home_val_info'] ) ? strip_tags( $new_instance['home_val_info'] ) : 0;
137
138
139
		return $instance;
140
	}
141
}
142
143
/**
144
 * Register Zillow Large Search Box.
145
 *
146
 * @access public
147
 * @return void
148
 */
149
function repro_zillow_search_box_widget() {
150
151
	register_widget( 'ZillowLargeSearchBox' );
152
}
153
add_action( 'widgets_init', 'repro_zillow_search_box_widget' );
154