From ed276fc8c828031faf5fa9859792196e50b3be0e Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Fri, 12 Dec 2025 21:59:26 -0400 Subject: [PATCH 1/3] Add ternary to null coalescing php cs fixer rule --- .php-cs-fixer.php | 1 + css/_single_theme.css.php | 2 +- tests/phpunit/base/FrmUnitTest.php | 2 +- tests/phpunit/entries/test_FrmShowEntryShortcode.php | 4 ++-- tests/phpunit/stripe/FrmStrpLiteUnitTest.php | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index c83430ffa4..e1b42d74a2 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -23,6 +23,7 @@ 'no_extra_blank_lines' => true, 'no_trailing_whitespace' => true, 'no_whitespace_in_blank_line' => true, + 'ternary_to_null_coalescing' => true, 'blank_line_before_statement' => array( 'statements' => array( 'try', diff --git a/css/_single_theme.css.php b/css/_single_theme.css.php index 885160851e..2b754470dd 100644 --- a/css/_single_theme.css.php +++ b/css/_single_theme.css.php @@ -6,7 +6,7 @@ $settings = FrmStylesHelper::get_settings_for_output( $style ); extract( $settings ); // phpcs:ignore WordPress.PHP.DontExtract -$is_loaded_via_ajax = isset( $is_loaded_via_ajax ) ? $is_loaded_via_ajax : false; +$is_loaded_via_ajax = $is_loaded_via_ajax ?? false; FrmStylesPreviewHelper::get_additional_preview_style( $settings, $is_loaded_via_ajax ); $important = empty( $important_style ) ? '' : ' !important'; diff --git a/tests/phpunit/base/FrmUnitTest.php b/tests/phpunit/base/FrmUnitTest.php index 4ec0b51963..862e194986 100644 --- a/tests/phpunit/base/FrmUnitTest.php +++ b/tests/phpunit/base/FrmUnitTest.php @@ -273,7 +273,7 @@ public function get_all_fields_for_form_key( $form_key ) { $this->contact_form_key => $this->contact_form_field_count, $this->repeat_sec_form_key => 3, ); - $expected_field_num = isset( $field_totals[ $form_key ] ) ? $field_totals[ $form_key ] : 0; + $expected_field_num = $field_totals[ $form_key ] ?? 0; $form_id = $this->factory->form->get_id_by_key( $form_key ); $fields = FrmField::get_all_for_form( $form_id, '', 'include' ); diff --git a/tests/phpunit/entries/test_FrmShowEntryShortcode.php b/tests/phpunit/entries/test_FrmShowEntryShortcode.php index 7662442c81..e76e3d4575 100644 --- a/tests/phpunit/entries/test_FrmShowEntryShortcode.php +++ b/tests/phpunit/entries/test_FrmShowEntryShortcode.php @@ -790,7 +790,7 @@ protected function table_header( $atts ) { $defaults = $this->get_defaults(); $atts = array_merge( $defaults, $atts ); $font_size = $atts['font_size']; - $border_width = isset( $atts['border_width'] ) ? $atts['border_width'] : $atts['field_border_width']; + $border_width = $atts['border_width'] ?? $atts['field_border_width']; $border_color = $atts['border_color']; $header .= ' style="border-spacing:0;font-size:' . $font_size . ';line-height:135%;'; @@ -980,7 +980,7 @@ protected function get_field_value( $entry, $field, $atts ) { if ( $field->field_key === 'free-html-field' ) { $field_value = 'Lorem ipsum.'; } else { - $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : ''; + $field_value = $entry->metas[ $field->id ] ?? ''; if ( is_array( $field_value ) ) { $field_value = implode( ', ', $field_value ); diff --git a/tests/phpunit/stripe/FrmStrpLiteUnitTest.php b/tests/phpunit/stripe/FrmStrpLiteUnitTest.php index 356ee9b993..0884597910 100644 --- a/tests/phpunit/stripe/FrmStrpLiteUnitTest.php +++ b/tests/phpunit/stripe/FrmStrpLiteUnitTest.php @@ -162,7 +162,7 @@ protected function get_plan_options() { return array_filter( array_merge( $default_options, - isset( $this->plan_options ) ? $this->plan_options : array() + $this->plan_options ?? array() ) ); } @@ -275,7 +275,7 @@ private function get_subscription_charge_options( $customer_id, $plan_id ) { return array_filter( array_merge( $default_options, - isset( $this->subscription_charge_options ) ? $this->subscription_charge_options : array() + $this->subscription_charge_options ?? array() ) ); } From b5f60b14cf54a625fb26967d0b53432c0fb5d45d Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Fri, 12 Dec 2025 22:01:36 -0400 Subject: [PATCH 2/3] Also add no_null_property_initialization rule --- .php-cs-fixer.php | 1 + tests/phpunit/emails/test_FrmEmail.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index e1b42d74a2..3e73e17322 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -24,6 +24,7 @@ 'no_trailing_whitespace' => true, 'no_whitespace_in_blank_line' => true, 'ternary_to_null_coalescing' => true, + 'no_null_property_initialization' => true, 'blank_line_before_statement' => array( 'statements' => array( 'try', diff --git a/tests/phpunit/emails/test_FrmEmail.php b/tests/phpunit/emails/test_FrmEmail.php index f932a192b6..929c6e7dcc 100644 --- a/tests/phpunit/emails/test_FrmEmail.php +++ b/tests/phpunit/emails/test_FrmEmail.php @@ -24,17 +24,17 @@ class test_FrmEmail extends FrmUnitTest { /** * @var stdClass */ - protected $contact_form = null; + protected $contact_form; /** * @var stdClass */ - protected $email_action = null; + protected $email_action; /** * @var stdClass */ - protected $entry = null; + protected $entry; public static function wpSetUpBeforeClass() { $_POST = array(); From bf3d5e56e6fcead37f10a03975dff60535763aca Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Fri, 12 Dec 2025 22:06:51 -0400 Subject: [PATCH 3/3] Remove some phpstan exceptions --- phpstan.neon | 4 ---- 1 file changed, 4 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index b644d068ea..70f272a630 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -192,7 +192,6 @@ parameters: - classes/controllers/FrmFormActionsController.php - classes/controllers/FrmFormTemplatesController.php - classes/controllers/FrmFormsController.php - - classes/controllers/FrmSettingsController.php - classes/controllers/FrmStylesController.php - classes/helpers/FrmAppHelper.php - classes/helpers/FrmCSVExportHelper.php @@ -210,15 +209,12 @@ parameters: - classes/models/FrmField.php - classes/models/FrmForm.php - classes/models/FrmFormAction.php - - classes/models/FrmMigrate.php - classes/models/FrmSettings.php - classes/models/FrmStyle.php - classes/models/fields/FrmFieldType.php - - square/controllers/FrmSquareLiteSettingsController.php - stripe/controllers/FrmStrpLiteActionsController.php - stripe/controllers/FrmTransLiteActionsController.php - stripe/helpers/FrmStrpLiteConnectHelper.php - - stripe/helpers/FrmTransLiteActionsHelper.php - stripe/helpers/FrmTransLiteAppHelper.php - stripe/models/FrmStrpLiteAuth.php - stripe/models/FrmTransLiteAction.php