ZillowLargeRateTableWidget   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 89
loc 89
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A form() 17 17 2
A __construct() 12 12 1
A widget() 16 16 3
A update() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 Rate Table Widget (https://www.zillow.com/webtools/widgets/large-rate-table-widget/)
8
 *
9
 * @package RE-PRO
10
 */
11
12
/**
13
 * ZillowLargeRateTableWidget class.
14
 *
15
 * @extends WP_Widget
16
 */
17 View Code Duplication
class ZillowLargeRateTableWidget 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...
Duplication introduced by
This class 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...
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_lg_ratetable_widget',
30
			__( 'Zillow Large Mortgage Rate Table', 're-pro' ),
31
			array(
32
				'description' => __( 'Display a large Mortgage Rate Table from Zillow.', 're-pro' ),
33
				'classname'   => 're-pro re-pro-widget zillow-widget zillow-widget-lg-rate-table',
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
52
53
		echo $args['before_widget'];
54
55
		echo $args['before_title'] . esc_attr( $title ) . $args['after_title'];
56
57
		$zillow_widgets = new ZillowWidgets();
58
59
		return $zillow_widgets->get_mortage_rate_widget( $iframe_id );
60
61
		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...
62
	}
63
64
	/**
65
	 * Form function.
66
	 *
67
	 * @access public
68
	 * @param mixed $instance Instance.
69
	 * @return void
70
	 */
71
	public function form( $instance ) {
72
73
		// Set default values.
74
		$instance = wp_parse_args( (array) $instance, array(
75
			'title' => '',
76
		));
77
78
		// Retrieve an existing value from the database.
79
		$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
80
81
		// Title.
82
		echo '<p>';
83
		echo '	<label for="' . $this->get_field_id( 'title' ) . '" class="title-label">' . __( 'Tile:', 're-pro' ) . '</label>';
84
		echo '	<input id="' . $this->get_field_id( 'title' ) . '" name="' . $this->get_field_name( 'title' ) . '" value="' . $title  . '" class="widefat">';
85
		echo '</p>';
86
87
	}
88
89
	/**
90
	 * Update Widget Instance.
91
	 *
92
	 * @access public
93
	 * @param mixed $new_instance New Instance.
94
	 * @param mixed $old_instance Old Instance.
95
	 * @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...
96
	 */
97
	public function update( $new_instance, $old_instance ) {
98
99
		$instance = $old_instance;
100
101
		$instance['title'] = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
102
103
		return $instance;
104
	}
105
}
106
107
/**
108
 * Register Zillow Affordability Calculator Widget.
109
 *
110
 * @access public
111
 * @return void
112
 */
113
/*function repro_zillow_rate_table_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...
114
115
	register_widget( 'ZillowLargeRateTableWidget' );
116
}
117
add_action( 'widgets_init', 'repro_zillow_rate_table_widget' );*/
118