Skip to content

Commit c2bf4cf

Browse files
committed
PHPCS fixes.
1 parent 6587309 commit c2bf4cf

24 files changed

+437
-178
lines changed

includes/admin/settings-page.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
*/
66
class Stellar_Places_Settings_Page {
77

8+
/**
9+
* Initialization function.
10+
*/
811
public static function initialize() {
912
add_action( 'admin_menu', array( __CLASS__, 'add_submenu_page' ) );
1013
add_action( 'admin_init', array( __CLASS__, 'settings_init' ) );
1114
}
1215

16+
/**
17+
* Add a submenu page.
18+
*/
1319
public static function add_submenu_page() {
1420
add_submenu_page(
1521
'edit.php?post_type=stlr_place',
@@ -21,6 +27,9 @@ public static function add_submenu_page() {
2127
);
2228
}
2329

30+
/**
31+
* Register settings.
32+
*/
2433
public static function settings_init() {
2534

2635
register_setting( 'stellar-places-settings', 'stellar_places_google_maps_api_key', 'sanitize_text_field' );
@@ -46,18 +55,28 @@ public static function settings_init() {
4655

4756
}
4857

58+
/**
59+
* Display a text field.
60+
*
61+
* @param array $args Field args.
62+
*/
4963
public static function text_field( $args ) {
5064
?>
51-
<input type="text"
52-
class="widefat"
53-
name="<?php echo esc_attr( $args['name'] ); ?>"
54-
value="<?php echo esc_attr( get_option( $args['name'] ) ); ?>"/>
65+
<input
66+
type="text"
67+
class="widefat"
68+
name="<?php echo esc_attr( $args['name'] ); ?>"
69+
value="<?php echo esc_attr( get_option( $args['name'] ) ); ?>"
70+
/>
5571
<?php if ( isset( $args['description'] ) ) { ?>
56-
<p class="description"><?php echo $args['description']; ?></p>
72+
<p class="description"><?php echo $args['description']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
5773
<?php
58-
}
74+
}
5975
}
6076

77+
/**
78+
* Render the page.
79+
*/
6180
public static function render() {
6281
?>
6382
<form action='options.php' method='post'>

includes/classes/content-prepender.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,32 @@
55
*/
66
class Stellar_Places_Content_Prepender {
77

8-
protected $_content = '';
8+
/**
9+
* The content to be prepended.
10+
*
11+
* @var string
12+
*/
13+
protected $content = '';
914

1015
/**
1116
* Set content and call 'prepend' method at the appropriate time
1217
*
13-
* @param string $content
18+
* @param string $content The content to be prepended.
1419
*/
15-
function __construct( $content ) {
16-
$this->_content = $content;
20+
public function __construct( $content ) {
21+
$this->content = $content;
1722
add_filter( 'the_content', array( $this, 'prepend' ) );
1823
}
1924

2025
/**
2126
* Prepend content
2227
*
23-
* @param string $content
28+
* @param string $content The content to be prepended.
29+
*
2430
* @return string
2531
*/
2632
public function prepend( $content ) {
27-
return $this->_content . $content;
33+
return $this->content . $content;
2834
}
2935

3036
}

includes/classes/google-map.php

Lines changed: 87 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,67 @@
55
*/
66
class Stellar_Places_Google_Map {
77

8-
// HTML Attributes
9-
public $id = '';
10-
public $class = '';
11-
public $width = '100%';
8+
/**
9+
* HTML ID.
10+
*
11+
* @var string
12+
*/
13+
public $id = '';
14+
15+
/**
16+
* HTML class.
17+
*
18+
* @var string
19+
*/
20+
public $class = '';
21+
22+
/**
23+
* HTML element width.
24+
*
25+
* @var string
26+
*/
27+
public $width = '100%';
28+
29+
/**
30+
* HTML element height.
31+
*
32+
* @var string
33+
*/
1234
public $height = '350px';
1335

14-
// Map Center
15-
public $latitude = 0;
36+
/**
37+
* Map center - latitude.
38+
*
39+
* @var int
40+
*/
41+
public $latitude = 0;
42+
43+
/**
44+
* Map center - longitude.
45+
*
46+
* @var int
47+
*/
1648
public $longitude = 0;
1749

18-
// Custom Map Options
19-
public $autoZoom = true;
50+
/**
51+
* Map option: autoZoom
52+
*
53+
* @var bool
54+
*/
55+
public $autoZoom = true;
56+
57+
/**
58+
* Map option: infoWindows
59+
*
60+
* @var bool
61+
*/
2062
public $infoWindows = true;
2163

22-
// Google Map Options
64+
/**
65+
* Google Map Options
66+
*
67+
* @var array
68+
*/
2369
public $mapOptions = array(
2470
'backgroundColor' => null,
2571
'disableDefaultUI' => null,
@@ -55,13 +101,17 @@ class Stellar_Places_Google_Map {
55101
'zoomControlOptions' => null,
56102
);
57103

58-
// Locations
59-
protected $_locations = array();
104+
/**
105+
* Locations
106+
*
107+
* @var array
108+
*/
109+
protected $locations = array();
60110

61111
/**
62112
* Instantiate class
63113
*
64-
* @param mixed $args
114+
* @param mixed $args Arguments.
65115
*/
66116
public function __construct( $args = null ) {
67117
if ( is_object( $args ) ) {
@@ -81,20 +131,20 @@ public function __construct( $args = null ) {
81131
/**
82132
* Add a location
83133
*
84-
* @param Stellar_Places_Place_Model $place
134+
* @param Stellar_Places_Place_Model $place Place model.
85135
*/
86136
public function add_location( Stellar_Places_Place_Model $place ) {
87-
$this->_locations[] = $place;
137+
$this->locations[] = $place;
88138
}
89139

90140
/**
91141
* Add a location
92142
*
93-
* @param WP_Post $post
143+
* @param WP_Post $post The post object.
94144
*/
95145
public function set_location( WP_Post $post ) {
96-
$this->_locations = array();
97-
$place = Stellar_Places::get_place_object( $post );
146+
$this->locations = array();
147+
$place = Stellar_Places::get_place_object( $post );
98148
if ( $place ) {
99149
$this->add_location( $place );
100150
}
@@ -103,11 +153,11 @@ public function set_location( WP_Post $post ) {
103153
/**
104154
* Set all locations at once
105155
*
106-
* @param WP_Query $query
156+
* @param WP_Query $query The query object.
107157
*/
108158
public function set_locations( WP_Query $query ) {
109-
$this->_locations = array();
110-
$posts = $query->get_posts();
159+
$this->locations = array();
160+
$posts = $query->get_posts();
111161
foreach ( $posts as $post ) {
112162
$place = Stellar_Places::get_place_object( $post );
113163
if ( $place ) {
@@ -133,7 +183,7 @@ public function get_html() {
133183
$style = "width: {$this->width}; height: {$this->height};";
134184
$autoZoom = filter_var( $this->autoZoom, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
135185
$infoWindows = filter_var( $this->infoWindows, FILTER_VALIDATE_BOOLEAN ) ? 'true' : 'false';
136-
$mapOptions = array_filter( $this->mapOptions, array( $this, '_is_not_null' ) );
186+
$mapOptions = array_filter( $this->mapOptions, array( $this, 'is_not_null' ) );
137187

138188
// Load JS and CSS
139189
wp_enqueue_script( 'stellar-places-map' );
@@ -148,15 +198,17 @@ public function get_html() {
148198

149199
ob_start();
150200
?>
151-
<div id="<?php echo esc_attr( $this->id ); ?>"
152-
class="<?php echo esc_attr( $class ); ?>"
153-
style="<?php echo esc_attr( $style ); ?>"
154-
data-stellar-places-map-auto-zoom="<?php echo esc_attr( $autoZoom ); ?>"
155-
data-stellar-places-map-info-windows="<?php echo esc_attr( $infoWindows ); ?>"
156-
data-stellar-places-map-lat="<?php echo esc_attr( $this->latitude ); ?>"
157-
data-stellar-places-map-lng="<?php echo esc_attr( $this->longitude ); ?>"
158-
data-stellar-places-map-locations="<?php echo esc_attr( json_encode( $this->_locations ) ); ?>"
159-
data-stellar-places-map-options="<?php echo esc_attr( json_encode( $mapOptions ) ); ?>"></div>
201+
<div
202+
id="<?php echo esc_attr( $this->id ); ?>"
203+
class="<?php echo esc_attr( $class ); ?>"
204+
style="<?php echo esc_attr( $style ); ?>"
205+
data-stellar-places-map-auto-zoom="<?php echo esc_attr( $autoZoom ); ?>"
206+
data-stellar-places-map-info-windows="<?php echo esc_attr( $infoWindows ); ?>"
207+
data-stellar-places-map-lat="<?php echo esc_attr( $this->latitude ); ?>"
208+
data-stellar-places-map-lng="<?php echo esc_attr( $this->longitude ); ?>"
209+
data-stellar-places-map-locations="<?php echo esc_attr( wp_json_encode( $this->locations ) ); ?>"
210+
data-stellar-places-map-options="<?php echo esc_attr( wp_json_encode( $mapOptions ) ); ?>"
211+
></div>
160212
<?php
161213
return ob_get_clean();
162214
}
@@ -165,7 +217,7 @@ class="<?php echo esc_attr( $class ); ?>"
165217
* Render map
166218
*/
167219
public function render() {
168-
echo $this->get_html();
220+
echo $this->get_html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
169221
}
170222

171223
/**
@@ -177,17 +229,18 @@ public static function wp_print_footer_scripts() {
177229
$template = dirname( STELLAR_PLACES_FILE ) . '/includes/templates/info-window.html';
178230
}
179231
echo '<script type="text/template" id="stellar-places-info-window-template">';
180-
echo file_get_contents( $template );
232+
echo file_get_contents( $template ); // phpcs:ignore
181233
echo '</script>';
182234
}
183235

184236
/**
185237
* Helper function to check if a value is not null
186238
*
187-
* @param mixed $value
239+
* @param mixed $value The value.
240+
*
188241
* @return bool
189242
*/
190-
protected function _is_not_null( $value ) {
243+
protected function is_not_null( $value ) {
191244
return ! is_null( $value );
192245
}
193246

includes/classes/google-static-map.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ class Stellar_Places_Google_Static_Map {
4343
*
4444
* @var array
4545
*/
46-
protected $_markers = array();
46+
protected $markers = array();
4747

4848
/**
4949
* Convert a location array into a string
5050
*
51-
* @param array $location
51+
* @param array $location Geocoordinates.
52+
*
5253
* @return mixed
5354
*/
5455
public function get_location_string( array $location ) {
@@ -58,13 +59,13 @@ public function get_location_string( array $location ) {
5859
/**
5960
* Add a marker to the map
6061
*
61-
* @param string $location
62-
* @param bool $color
63-
* @param bool $label
64-
* @param bool $size
62+
* @param string $location Location.
63+
* @param bool $color Color.
64+
* @param bool $label Label.
65+
* @param bool $size Size.
6566
*/
66-
function add_marker( $location, $color = false, $label = false, $size = false ) {
67-
$this->_markers[] = array_filter(
67+
public function add_marker( $location, $color = false, $label = false, $size = false ) {
68+
$this->markers[] = array_filter(
6869
array(
6970
'color' => $color,
7071
'label' => $label,
@@ -79,22 +80,22 @@ function add_marker( $location, $color = false, $label = false, $size = false )
7980
*
8081
* @return string
8182
*/
82-
function get_src() {
83+
public function get_src() {
8384
$parameters = array(
8485
'size' => $this->size,
8586
'zoom' => $this->zoom,
8687
'scale' => 2,
8788
);
88-
if ( empty( $this->_markers ) ) {
89+
if ( empty( $this->markers ) ) {
8990
$parameters['center'] = $this->center;
9091
}
9192
$query_string = http_build_query( $parameters );
92-
if ( ! empty( $this->_markers ) ) {
93+
if ( ! empty( $this->markers ) ) {
9394
$markers = '';
94-
foreach ( $this->_markers as $marker ) {
95+
foreach ( $this->markers as $marker ) {
9596
$properties = array();
9697
foreach ( $marker as $name => $value ) {
97-
if ( 'location' == $name ) {
98+
if ( 'location' === $name ) {
9899
$properties[] = $value;
99100
} else {
100101
$properties[] = "{$name}:{$value}";
@@ -105,6 +106,7 @@ function get_src() {
105106
$query_string .= $markers;
106107
}
107108
$src = self::URL . $query_string;
109+
108110
return $src;
109111
}
110112

@@ -113,13 +115,14 @@ function get_src() {
113115
*
114116
* @return string
115117
*/
116-
function get_html() {
118+
public function get_html() {
117119
list( $width, $height ) = explode( 'x', $this->size );
118120
$attributes = 'src="' . esc_url( $this->get_src() ) . '"';
119121
$attributes .= 'width="' . esc_attr( $width ) . '"';
120122
$attributes .= 'height="' . esc_attr( $height ) . '"';
121123
$attributes .= 'alt="' . esc_attr( $this->alt ) . '"';
122124
$html = '<img ' . $attributes . ' />';
125+
123126
return $html;
124127
}
125128

0 commit comments

Comments
 (0)