ZillowContactWidget   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 112
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
B widget() 0 18 6
C form() 0 36 7
B update() 0 10 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 Contact Widget (https://www.zillow.com/webtools/widgets/contact-form-widget.htm)
8
 *
9
 * @package RE-PRO
10
 */
11
12
/**
13
 * ZillowContactWidget class.
14
 *
15
 * @extends WP_Widget
16
 */
17
class ZillowContactWidget 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_contact_widget',
30
			__( 'Zillow Contact Form', 're-pro' ),
31
			array(
32
				'description' => __( 'Display a form to contact you on Zillow.', 're-pro' ),
33
				'classname'   => 're-pro re-pro-widget zillow-widget zillow-widget-contact',
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
		$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...
52
		$email = ! empty( $instance['email'] ) ? $instance['email'] : '';
53
		$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : '';
0 ignored issues
show
Unused Code introduced by
$zuid 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...
54
55
		echo $args['before_widget'];
56
57
		echo $args['before_title'] . esc_attr( $title ) . $args['after_title'];
58
59
		$zillow_widgets = new ZillowWidgets();
60
61
		return $zillow_widgets->get_contact_widget( $iframe_id, $email );
62
63
		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...
64
	}
65
66
	/**
67
	 * Form function.
68
	 *
69
	 * @access public
70
	 * @param mixed $instance Instance.
71
	 * @return void
72
	 */
73
	public function form( $instance ) {
74
75
		// Set default values.
76
		$instance = wp_parse_args( (array) $instance, array(
77
			'title' => '',
78
			'screenname' => '',
79
			'zuid' => '',
80
		));
81
82
		// Retrieve an existing value from the database.
83
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
84
		$screenname = ! empty( $instance['screenname'] ) ? $instance['screenname'] : '';
85
		$zuid = ! empty( $instance['zuid'] ) ? $instance['zuid'] : '';
86
		$size = ! empty( $instance['size'] ) ? $instance['size'] : '';
0 ignored issues
show
Unused Code introduced by
$size 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...
87
		$height = ! empty( $instance['height'] ) ? $instance['height'] : '';
0 ignored issues
show
Unused Code introduced by
$height 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...
88
		$width = ! empty( $instance['width'] ) ? $instance['width'] : '';
0 ignored issues
show
Unused Code introduced by
$width 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...
89
90
		// Title.
91
		echo '<p>';
92
		echo '	<label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>';
93
		echo '	<input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title  . '" class="widefat">';
94
		echo '</p>';
95
96
		// Zillow Screenname.
97
		echo '<p>';
98
		echo '	<label for="' . $this->get_field_id( 'screenname' ) . '" class="title-label">' . __( 'Zillow Screenname:', 're-pro' ) . '</label>';
99
		echo '	<input id="' . $this->get_field_id( 'screenname' ) . '" name="' . $this->get_field_name( 'screenname' ) . '" value="' . $screenname  . '" class="widefat">';
100
		echo '</p>';
101
102
		// Zillow User ID.
103
		echo '<p>';
104
		echo '	<label for="' . $this->get_field_id( 'zuid' ) . '" class="title-label">' . __( 'Zillow User ID:', 're-pro' ) . '</label>';
105
		echo '	<input id="' . $this->get_field_id( 'zuid' ) . '" name="' . $this->get_field_name( 'zuid' ) . '" value="' . $zuid  . '" class="widefat">';
106
		echo '</p>';
107
108
	}
109
110
	/**
111
	 * Update.
112
	 *
113
	 * @access public
114
	 * @param mixed $new_instance New Instance.
115
	 * @param mixed $old_instance Old Instance.
116
	 * @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...
117
	 */
118
	public function update( $new_instance, $old_instance ) {
119
120
		$instance = $old_instance;
121
122
		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
123
		$instance['screenname'] = ! empty( $new_instance['screenname'] ) ? strip_tags( $new_instance['screenname'] ) : '';
124
		$instance['zuid'] = ! empty( $new_instance['zuid'] ) ? strip_tags( $new_instance['zuid'] ) : '';
125
		$instance['zmod'] = ! empty( $new_instance['zmod'] ) ? strip_tags( $new_instance['zmod'] ) : '';
126
		return $instance;
127
	}
128
}
129
130
/**
131
 * Register Zillow Review Widget.
132
 *
133
 * @access public
134
 * @return void
135
 */
136
/*function repro_zillow_contact_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...
137
138
	register_widget( 'ZillowContactWidget' );
139
}
140
add_action( 'widgets_init', 'repro_zillow_contact_widget' );*/
141