Skip to content

Commit d8003f7

Browse files
authored
Merge pull request #928 from GravityPDF/linting-errors
Update codebase to use strict comparisons
2 parents d4ae299 + f93bd93 commit d8003f7

45 files changed

Lines changed: 173 additions & 170 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

phpcs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<exclude-pattern>/tmp/*</exclude-pattern>
1111
<exclude-pattern>/dist/*</exclude-pattern>
1212
<exclude-pattern>*.js</exclude-pattern>
13+
<exclude-pattern>/src/helper/licensing/EDD_SL_Plugin_Updater.php</exclude-pattern>
1314
<exclude-pattern>/tests/phpunit/bootstrap.php</exclude-pattern>
1415
<exclude-pattern>/tests/phpunit/phpunit6-compat.php</exclude-pattern>
1516

src/bootstrap.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function plugin_action_links( $links ) {
330330
*/
331331
public function plugin_row_meta( $links, $file ) {
332332

333-
if ( $file == PDF_PLUGIN_BASENAME ) {
333+
if ( $file === PDF_PLUGIN_BASENAME ) {
334334
$row_meta = [
335335
'docs' => '<a href="' . esc_url( 'https://gravitypdf.com/documentation/v5/five-minute-install/' ) . '" title="' . esc_attr__( 'View Gravity PDF Documentation', 'gravity-forms-pdf-extended' ) . '">' . esc_html__( 'Docs', 'gravity-forms-pdf-extended' ) . '</a>',
336336
'support' => '<a href="' . esc_url( $this->data->settings_url . '&tab=help' ) . '" title="' . esc_attr__( 'Get Help and Support', 'gravity-forms-pdf-extended' ) . '">' . esc_html__( 'Support', 'gravity-forms-pdf-extended' ) . '</a>',
@@ -466,7 +466,7 @@ public function load_admin_assets() {
466466
wp_enqueue_script( 'gfpdf_js_backbone' );
467467
}
468468

469-
if ( rgget( 'page' ) == 'gf_entries' ) {
469+
if ( rgget( 'page' ) === 'gf_entries' ) {
470470
wp_enqueue_script( 'gfpdf_js_entries' );
471471
wp_enqueue_style( 'gfpdf_css_styles' );
472472
}
@@ -956,10 +956,10 @@ public function get_default_config_data( $form_id ) {
956956
}
957957

958958
return [
959-
'empty_field' => ( isset( $settings['show_empty'] ) && $settings['show_empty'] == 'Yes' ) ? true : false,
960-
'html_field' => ( isset( $settings['show_html'] ) && $settings['show_html'] == 'Yes' ) ? true : false,
961-
'page_names' => ( isset( $settings['show_page_names'] ) && $settings['show_page_names'] == 'Yes' ) ? true : false,
962-
'section_content' => ( isset( $settings['show_section_content'] ) && $settings['show_section_content'] == 'Yes' ) ? true : false,
959+
'empty_field' => ( isset( $settings['show_empty'] ) && $settings['show_empty'] === 'Yes' ) ? true : false,
960+
'html_field' => ( isset( $settings['show_html'] ) && $settings['show_html'] === 'Yes' ) ? true : false,
961+
'page_names' => ( isset( $settings['show_page_names'] ) && $settings['show_page_names'] === 'Yes' ) ? true : false,
962+
'section_content' => ( isset( $settings['show_section_content'] ) && $settings['show_section_content'] === 'Yes' ) ? true : false,
963963
];
964964
}
965965
}

src/controller/Controller_Actions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function route_notices() {
196196

197197
/* Prevent actions being displayed on our welcome pages */
198198
if ( ! is_admin() ||
199-
( rgget( 'page' ) == 'gfpdf-getting-started' ) || ( rgget( 'page' ) == 'gfpdf-update' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
199+
( rgget( 'page' ) === 'gfpdf-getting-started' ) || ( rgget( 'page' ) === 'gfpdf-update' ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX )
200200
) {
201201
return null;
202202
}
@@ -234,7 +234,7 @@ public function route() {
234234
foreach ( $this->get_routes() as $route ) {
235235

236236
/* Check we have a valid action and the display condition is true */
237-
if ( rgpost( 'gfpdf_action' ) == 'gfpdf_' . $route['action'] && call_user_func( $route['condition'] ) ) {
237+
if ( rgpost( 'gfpdf_action' ) === 'gfpdf_' . $route['action'] && call_user_func( $route['condition'] ) ) {
238238

239239
/* Check user capability */
240240
if ( ! $this->gform->has_capability( $route['capability'] ) ) {

src/controller/Controller_PDF.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function process_pdf_endpoint() {
237237

238238
$pid = $GLOBALS['wp']->query_vars['pid'];
239239
$lid = (int) $GLOBALS['wp']->query_vars['lid'];
240-
$action = ( ( isset( $GLOBALS['wp']->query_vars['action'] ) ) && $GLOBALS['wp']->query_vars['action'] == 'download' ) ? 'download' : 'view';
240+
$action = ( ( isset( $GLOBALS['wp']->query_vars['action'] ) ) && $GLOBALS['wp']->query_vars['action'] === 'download' ) ? 'download' : 'view';
241241

242242
$this->log->addNotice(
243243
'Processing PDF endpoint.',
@@ -367,7 +367,7 @@ private function pdf_error( $error ) {
367367

368368
/* only display detailed error to admins */
369369
$whitelist_errors = [ 'timeout_expired', 'access_denied' ];
370-
if ( $this->gform->has_capability( 'gravityforms_view_settings' ) || in_array( $error->get_error_code(), $whitelist_errors ) ) {
370+
if ( $this->gform->has_capability( 'gravityforms_view_settings' ) || in_array( $error->get_error_code(), $whitelist_errors, true ) ) {
371371
wp_die( $error->get_error_message() );
372372
} else {
373373
wp_die( esc_html__( 'There was a problem generating your PDF', 'gravity-forms-pdf-extended' ) );

src/controller/Controller_Save_Core_Fonts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function download_and_save_font( $fontname ) {
165165
return false;
166166
}
167167

168-
if ( $res_code != '200' ) {
168+
if ( $res_code !== 200 ) {
169169
$this->log->addError(
170170
'Core Font API Response Failed',
171171
[

src/deprecated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class="default entry-view-page-break"><?php echo $form['pagination']['pages'][ $
457457
$excluded = [ 'captcha', 'password', 'page' ];
458458

459459
/* Skip over any fields we don't want to include */
460-
if ( in_array( $input, $excluded ) ) {
460+
if ( in_array( $input, $excluded, true ) ) {
461461
continue;
462462
}
463463

@@ -467,7 +467,7 @@ class="default entry-view-page-break"><?php echo $form['pagination']['pages'][ $
467467
self::load_legacy_css( $field );
468468

469469
/* Check if HTML field should be included */
470-
if ( $input == 'html' ) {
470+
if ( $input === 'html' ) {
471471

472472
if ( $config['html_field'] === true ) {
473473
$html = $class->html();

src/helper/Helper_Field_Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ private function handle_open_container( GF_Field $field ) {
302302
*/
303303
private function process_skipped_fields( GF_Field $field ) {
304304
/* if we have a skipped field and the container is open we will close it */
305-
if ( in_array( $field->type, $this->skip_fields ) ) {
305+
if ( in_array( $field->type, $this->skip_fields, true ) ) {
306306
$this->strip_field_of_any_classmaps( $field );
307307
$this->close();
308308

src/helper/Helper_Logger.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ protected function setup_logger() {
134134

135135
/* Set the logger timezone once (if needed) */
136136
if ( ! $timezone ) {
137-
$offset = get_option( 'gmt_offset' );
137+
$offset = (float) get_option( 'gmt_offset' );
138138

139-
if ( $offset != 0 ) {
139+
if ( $offset !== 0.0 ) {
140140
try {
141141
$timezone = new DateTimeZone( ( $offset > 0 ) ? '+' . $offset : $offset );
142142
Logger::setTimezone( $timezone );

src/helper/Helper_Migration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private function process_individual_v3_nodes( $node, $migration_key = [] ) {
276276

277277
/* Fix the public access key */
278278
if ( isset( $node['access'] ) ) {
279-
$node['access'] = ( $node['access'] == 'all' ) ? 'Yes' : 'No';
279+
$node['access'] = ( $node['access'] === 'all' ) ? 'Yes' : 'No';
280280
}
281281

282282
/* Remove .php from the template file */
@@ -293,7 +293,7 @@ private function process_individual_v3_nodes( $node, $migration_key = [] ) {
293293
if ( isset( $node['pdf_size'] ) && is_array( $node['pdf_size'] ) ) {
294294

295295
/* Ensure it's in the correct format */
296-
if ( sizeof( $node['pdf_size'] ) == 2 ) {
296+
if ( sizeof( $node['pdf_size'] ) === 2 ) {
297297
$node['pdf_size'][0] = (int) $node['pdf_size'][0];
298298
$node['pdf_size'][1] = (int) $node['pdf_size'][1];
299299
$node['pdf_size'][2] = 'millimeters';
@@ -312,7 +312,7 @@ private function process_individual_v3_nodes( $node, $migration_key = [] ) {
312312

313313
/* Convert our boolean values into 'Yes' or 'No' responses, with the exception of notification */
314314
$skip_nodes = [ 'notifications', 'notification' ];
315-
if ( ! in_array( $id, $skip_nodes ) ) {
315+
if ( ! in_array( $id, $skip_nodes, true ) ) {
316316
$val = $this->misc->update_deprecated_config( $val );
317317
}
318318

@@ -337,7 +337,7 @@ private function process_individual_v3_nodes( $node, $migration_key = [] ) {
337337
*/
338338
private function process_v3_configuration( $raw_config ) {
339339

340-
if ( ! is_array( $raw_config['config'] ) || sizeof( $raw_config['config'] ) == 0 ) {
340+
if ( ! is_array( $raw_config['config'] ) || sizeof( $raw_config['config'] ) === 0 ) {
341341
return [];
342342
}
343343

@@ -467,7 +467,7 @@ private function import_v3_config( $config ) {
467467
foreach ( $form['notifications'] as $notification ) {
468468
$event = ( isset( $notification['event'] ) ) ? $notification['event'] : '';
469469

470-
if ( ! in_array( $event, $omit ) ) {
470+
if ( ! in_array( $event, $omit, true ) ) {
471471
$notifications[ $notification['id'] ] = $notification['name'];
472472
}
473473
}
@@ -518,7 +518,7 @@ private function import_v3_config( $config ) {
518518

519519
$new_notification = [];
520520
foreach ( $node['notification'] as $email ) {
521-
$match = array_search( $email, $notifications );
521+
$match = array_search( $email, $notifications, true );
522522

523523
if ( $match !== false ) {
524524
$new_notification[] = $match;

src/helper/Helper_Misc.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ public function get_upload_details() {
536536
$upload_path = trim( get_option( 'upload_path' ) );
537537
$dir = $upload_path;
538538

539-
if ( empty( $upload_path ) || 'wp-content/uploads' == $upload_path ) {
539+
if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
540540
$dir = WP_CONTENT_DIR . '/uploads';
541541
} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
542542
/* $dir is absolute, $upload_path is (maybe) relative to ABSPATH */
@@ -545,7 +545,7 @@ public function get_upload_details() {
545545

546546
$url = get_option( 'upload_url_path' );
547547
if ( ! $url ) {
548-
if ( empty( $upload_path ) || ( 'wp-content/uploads' == $upload_path ) || ( $upload_path == $dir ) ) {
548+
if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path === $dir ) ) {
549549
$url = WP_CONTENT_URL . '/uploads';
550550
} else {
551551
$url = trailingslashit( $siteurl ) . $upload_path;
@@ -575,7 +575,7 @@ public function get_upload_details() {
575575
public function convert_url_to_path( $url ) {
576576

577577
/* If $url is empty we'll return early */
578-
if ( trim( $url ) == false ) {
578+
if ( empty( trim( $url ) ) ) {
579579
return $url;
580580
}
581581

@@ -633,7 +633,7 @@ public function convert_url_to_path( $url ) {
633633
public function convert_path_to_url( $path ) {
634634

635635
/* If $url is empty we'll return early */
636-
if ( trim( $path ) == false ) {
636+
if ( empty( trim( $path ) ) ) {
637637
return $path;
638638
}
639639

@@ -709,7 +709,7 @@ public function strip_invalid_characters( $name ) {
709709
public function get_legacy_ids( $entry_id, $settings ) {
710710

711711
$leads = rgget( 'lid' );
712-
$override = ( isset( $settings['public_access'] ) && $settings['public_access'] == 'Yes' ) ? true : false;
712+
$override = ( isset( $settings['public_access'] ) && $settings['public_access'] === 'Yes' ) ? true : false;
713713

714714
if ( $leads && ( $override === true || $this->gform->has_capability( 'gravityforms_view_entries' ) ) ) {
715715
$ids = explode( ',', $leads );
@@ -853,14 +853,14 @@ public function get_fields_sorted_by_id( $form_id ) {
853853
public function backwards_compat_conversion( $settings, $form, $entry ) {
854854

855855
$compat = [];
856-
$compat['premium'] = ( isset( $settings['advanced_template'] ) && $settings['advanced_template'] == 'Yes' ) ? true : false;
857-
$compat['rtl'] = ( isset( $settings['rtl'] ) && $settings['rtl'] == 'Yes' ) ? true : false;
856+
$compat['premium'] = ( isset( $settings['advanced_template'] ) && $settings['advanced_template'] === 'Yes' ) ? true : false;
857+
$compat['rtl'] = ( isset( $settings['rtl'] ) && $settings['rtl'] === 'Yes' ) ? true : false;
858858
$compat['dpi'] = ( isset( $settings['image_dpi'] ) ) ? (int) $settings['image_dpi'] : 96;
859-
$compat['security'] = ( isset( $settings['security'] ) && $settings['security'] == 'Yes' ) ? true : false;
859+
$compat['security'] = ( isset( $settings['security'] ) && $settings['security'] === 'Yes' ) ? true : false;
860860
$compat['pdf_password'] = ( isset( $settings['password'] ) ) ? $this->gform->process_tags( $settings['password'], $form, $entry ) : '';
861861
$compat['pdf_privileges'] = ( isset( $settings['privileges'] ) ) ? $settings['privileges'] : '';
862-
$compat['pdfa1b'] = ( isset( $settings['format'] ) && $settings['format'] == 'PDFA1B' ) ? true : false;
863-
$compat['pdfx1a'] = ( isset( $settings['format'] ) && $settings['format'] == 'PDFX1A' ) ? true : false;
862+
$compat['pdfa1b'] = ( isset( $settings['format'] ) && $settings['format'] === 'PDFA1B' ) ? true : false;
863+
$compat['pdfx1a'] = ( isset( $settings['format'] ) && $settings['format'] === 'PDFX1A' ) ? true : false;
864864

865865
return $compat;
866866
}
@@ -917,11 +917,13 @@ public function maybe_load_gf_entry_detail_class() {
917917
*/
918918
public function in_array( $needle, $haystack, $strict = true ) {
919919
foreach ( $haystack as $item ) {
920+
/* phpcs:disable */
920921
if ( ( $strict ? $item === $needle : $item == $needle ) ||
921922
( is_array( $item ) && $this->in_array( $needle, $item, $strict ) )
922923
) {
923924
return true;
924925
}
926+
/* phpcs:enable */
925927
}
926928

927929
return false;

0 commit comments

Comments
 (0)