HomesWidgets::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
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 15 and the first side effect is on line 9.

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
 * Homes.com Widgets Class
4
 *
5
 * @package RE-PRO
6
 */
7
8
// Exit if accessed directly.
9
if ( ! defined( 'ABSPATH' ) ) { exit; }
10
11
if ( ! class_exists( 'HomesWidgets' ) ) {
12
	/**
13
	 * HomesWidgets class.
14
	 */
15
	class HomesWidgets {
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...
16
17
		/**
18
		 * __construct function.
19
		 *
20
		 * @access public
21
		 * @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...
22
		 */
23
		public function __construct() {
24
		}
25
26
		/**
27
		 * Homes_iframe_css function.
28
		 *
29
		 * @access public
30
		 * @return void
31
		 */
32
		public function homes_iframe_css() {
33
		?>
34
35
		<style>
36
			.homes-iframe {
37
				display:block;
38
				max-width:100%;
39
			}
40
		</style>
41
42
		<?php
43
44
		}
45
46
		/**
47
		 * Homes iframe ID Names.
48
		 *
49
		 * @access public
50
		 * @param string $iframe_id (default: '').
51
		 * @return string $iframe_id.
52
		 */
53
		public function homes_iframe_id( $iframe_id = '' ) {
54
55
			if ( '' !== $iframe_id  ) {
56
				return sanitize_html_class( $iframe_id ) . '-iframe';
57
			}
58
59
		}
60
61
		/**
62
		 * Homes iframe Class Names.
63
		 *
64
		 * @access public
65
		 * @param string $widget_name (default: '').
66
		 * @return string class name.
67
		 */
68 View Code Duplication
		public function homes_iframe_class( $widget_name = '' ) {
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...
69
70
			if ( '' !== $widget_name ) {
71
				return 'homes homes-iframe homes-' . sanitize_html_class( $widget_name ) . '-iframe';
72
			} else {
73
				return 'homes homes-iframe';
74
			}
75
76
		}
77
78
		/* Homes WIDGETS. */
79
80
		/**
81
		 * Get Commute Time Widget.
82
		 *
83
		 * @access public
84
		 * @param string $iframe_id (default: '').
85
		 * @param mixed  $start_addr Start Address.
86
		 * @param mixed  $color Button Color.
87
		 * @return void
88
		 */
89
		public function get_commute_time_widget( $iframe_id = '', $start_addr, $color ) {
90
91
			echo '<div class="commute-time-widget">';
92
			echo '	<h1 style="color:#' . $color . '">Commute Time</h1>';
93
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="commute-time-frame '. $this->homes_iframe_class( 'commute-time-widget' ) .'" scrolling="no" title="'. __( 'Commute Time on Homes', 're-pro' ) .'" src="http://www.homes.com/widget/commute-time/frame/?show_only_destination=NO&text_color=%230054a0&direction_link=%2FHomesCom%2FInclude%2FListingDetail%2FMap%2FPrintDirections%2Ecfm%3FstartAddress%3D%25%25source%5Faddress%25%25%26endAddress%3D%25%25destination%5Faddress%25%25&button_color=%23' . $color .'&cobrand=&source_address=' . $start_addr . '"&property_id=" width="100%" seamless frameborder="0"></iframe>';
94
			echo '	<div class="footer">';
95
			echo '		<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
96
			echo '			Powered By Homes.com';
97
			echo '		</a>';
98
			echo '	</div>';
99
			echo '</div>';
100
101
		}
102
103
		/**
104
		 * Get Featured Listings Widget.
105
		 *
106
		 * @access public
107
		 * @param string $iframe_id (default: '').
108
		 * @param mixed  $location Location.
109
		 * @param mixed  $color Text Color.
110
		 * @param mixed  $status Listing Status.
111
		 * @return void
112
		 */
113
		public function get_featured_listings( $iframe_id = '', $location, $color, $status ) {
114
115
			if ( 'RENT' === $status ) {
116
				$showTitle = 'Rent';
117
			} else {
118
				$showTitle = 'Sale';
119
			}
120
121
			echo '<div class="featured-listings-widget">';
122
			echo '	<h1 style="color:#' . $color . '">Featured Homes for <span class="listing-stat">' . $showTitle . '</span></h1>';
123
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="featured-listings-frame '. $this->homes_iframe_class( 'featured-listings-widget' ) .'" scrolling="no" title="'. __( 'Featured Listings on Homes', 're-pro' ) .'" src="http://www.homes.com/widget/featured-listings/frame/?text_color=%23' . $color .'&listing_status=FOR%20' . $status .'&inner_color=%23' . $color .'&cobrand=&location=' . $location .'" width="100%" seamless frameborder="0"></iframe>';
124
			echo '	<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
125
			echo '		Powered By Homes.com';
126
			echo '	</a>';
127
			echo '</div>';
128
129
		}
130
131
		/**
132
		 * Get Home Values Widget.
133
		 *
134
		 * @access public
135
		 * @param string $iframe_id (default: '').
136
		 * @param mixed  $location Location.
137
		 * @param mixed  $firstColor Color 1.
138
		 * @param mixed  $secondColor Color 2.
139
		 * @param mixed  $average Average Value.
140
		 * @param mixed  $median Median Value.
141
		 * @return void
142
		 */
143
		public function get_home_values( $iframe_id = '', $location, $firstColor, $secondColor, $average, $median ) {
144
145
			$valueTypes = 'MEAN,MEDIAN';
146
			if ( $average && $median ) {
147
				$valueTypes = 'MEAN,MEDIAN';
148
			} else if ( $average ) {
149
				$valueTypes = 'MEAN';
150
			} else if ( $median ) {
151
				$valueTypes = 'MEDIAN';
152
			}
153
154
			echo '<div class="home-values-widget">';
155
			echo '	<h1 style="color:#' . $firstColor . '">Search Home Values</h1>';
156
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="home-values-frame '. $this->homes_iframe_class( 'home-values-widget' ) .'" scrolling="no" title="'. __( 'Home Values on Homes', 're-pro' ) .'"src="http://www.homes.com/widget/home-values/frame/?avm_types=' . $valueTypes .'&text_color=%23' . $firstColor .'&button_color=%23' . $secondColor .'&cobrand=&location=' . $location .'" width="100%" seamless frameborder="0"></iframe>';
157
			echo '	<div class="footer">';
158
			echo	'		<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
159
			echo '			Powered By Homes.com';
160
			echo '		</a>';
161
			echo '	</div>';
162
			echo '</div>';
163
164
		}
165
166
		/**
167
		 * Get Search Widget.
168
		 *
169
		 * @access public
170
		 * @param string $iframe_id (default: '').
171
		 * @param mixed  $location Location.
172
		 * @param mixed  $color Color.
173
		 * @param bool   $sale (default: true) For Sale homes.
174
		 * @param bool   $rent (default: true) For Rent homes.
175
		 * @return void
176
		 */
177 View Code Duplication
		public function get_search( $iframe_id = '', $location, $color, $sale, $rent ) {
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...
178
179
			if ( ( empty( $sale ) && empty( $rent ) ) || ( $sale && $rent ) ) {
180
				$searchTypes = 'FOR SALE,FOR RENT';
181
				$showTitle = '';
182
			} else if ( $sale ) {
183
				$searchTypes = 'FOR SALE';
184
				$showTitle = 'for Sale';
185
			} else if ( $rent ) {
186
				$searchTypes = 'FOR RENT';
187
				$showTitle = 'for Rent';
188
			}
189
190
			echo '<div class="medium-search-widget">';
191
			echo '	<h1 style="color:#' . $color . '">Search Homes <span class="listing-stat">' . $showTitle . '</span> </h1>';
0 ignored issues
show
Bug introduced by
The variable $showTitle does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
192
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="medium-search-frame '. $this->homes_iframe_class( 'search-widget' ) .'" scrolling="no" title="'. __( 'Search on Homes', 're-pro' ) .'"src="http://www.homes.com/widget/medium-search/frame/?text_color=%23' . $color .'&listing_status=' . $searchTypes .'&cobrand=&location=' . $location .'" width="100%" seamless frameborder="0"></iframe>';
0 ignored issues
show
Bug introduced by
The variable $searchTypes does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
193
			echo '	<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
194
			echo '		Powered By Homes.com';
195
			echo '	</a>';
196
			echo '</div>';
197
198
		}
199
200
		/**
201
		 * Get Mortgage Calculator Widget.
202
		 *
203
		 * @access public
204
		 * @param string $iframe_id (default: '').
205
		 * @param mixed  $color Color.
206
		 * @return void
207
		 */
208
		public function get_mortgage_calc( $iframe_id = '', $color ) {
209
210
			echo '<div class="mortgage-calculator-widget">';
211
			echo '	<h1 style="color:#' . $color . '">Mortgage Calculator</h1>';
212
			echo '	<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
213
			echo '		Powered By Homes.com';
214
			echo '	</a>';
215
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="mortgage-calculator-frame '. $this->homes_iframe_class( 'mortgage-calc-widget' ) .'" scrolling="no" title="'. __( 'Mortgage Calculator on Homes', 're-pro' ) .'"src="http://www.homes.com/widget/mortgage-calculator/frame/?text_color=%23' . $color .'&cobrand=" width="100%" seamless frameborder="0"></iframe>';
216
			echo '</div>';
217
218
		}
219
220
		/**
221
		 * Get Real Estate (Simple) Search Widget.
222
		 *
223
		 * @access public
224
		 * @param string $iframe_id (default: '').
225
		 * @param mixed  $location Location.
226
		 * @param mixed  $color Color.
227
		 * @param bool   $sale (default: true) For Sale homes.
228
		 * @param bool   $rent (default: true) For Rent homes.
229
		 * @return void
230
		 */
231 View Code Duplication
		public function get_simple_search( $iframe_id = '', $location, $color, $sale, $rent ) {
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...
232
233
			if ( ( empty( $sale ) && empty( $rent ) ) || ( $sale && $rent ) ) {
234
				$searchTypes = 'FOR SALE,FOR RENT';
235
				$showTitle = '';
236
			} else if ( $sale ) {
237
				$searchTypes = 'FOR SALE';
238
				$showTitle = 'for Sale';
239
			} else if ( $rent ) {
240
				$searchTypes = 'FOR RENT';
241
				$showTitle = 'for Rent';
242
			}
243
244
			echo '<div class="simple-search-widget">';
245
			echo '<h1 style="color:#' . $color . '">Search Homes <span class="listing-stat">' . $showTitle . '</span></h1>';
0 ignored issues
show
Bug introduced by
The variable $showTitle does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
246
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="simple-search-frame '. $this->homes_iframe_class( 'simple-search-widget' ) .'" scrolling="no" title="'. __( 'Simple Search on Homes', 're-pro' ) .'"src="http://www.homes.com/widget/simple-search/frame/?text_color=%23' . $color .'&listing_status=' . $searchTypes .'&cobrand=&location=' . $location .'" width="100%" seamless frameborder="0"></iframe>';
0 ignored issues
show
Bug introduced by
The variable $searchTypes does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
247
			echo '	<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
248
			echo '		Powered By Homes.com';
249
			echo '	</a>';
250
			echo '</div>';
251
		}
252
253
		/**
254
		 * Get Real Estate (Tall) Search Widget.
255
		 *
256
		 * @access public
257
		 * @param string $iframe_id (default: '').
258
		 * @param mixed  $location Location.
259
		 * @param mixed  $color Text Color.
260
		 * @param mixed  $status Listing Status.
261
		 * @return void
262
		 */
263
		public function get_tall_search( $iframe_id = '', $location, $color, $status ) {
264
265
			echo '<div class="tall-search-widget">';
266
			echo '	<h1 style="color:#' . $color . '">Search Homes</h1>';
267
			echo '	<iframe id="'. $this->homes_iframe_id( $iframe_id ) .'" class="tall-search-frame '. $this->homes_iframe_class( 'tall-search-widget' ) .'" scrolling="no" title="'. __( 'Tall Search on Homes', 're-pro' ) .'"src="http://www.homes.com/widget/tall-search/frame/?text_color=%23' . $color .'&listing_status=' . $status .'&cobrand=&location=' . $location .'" width="100%" seamless frameborder="0"></iframe>';
268
			echo '	<a href="http://www.homes.com/widgets/" title="Homes.com" class="logo">';
269
			echo '		Powered By Homes.com';
270
			echo '	</a>';
271
			echo '</div>';
272
		}
273
	}
274
}
275