Skip to content

Simplify null check#2752

Merged
Crabcyborg merged 1 commit into
masterfrom
simplify_null_check
Jan 9, 2026
Merged

Simplify null check#2752
Crabcyborg merged 1 commit into
masterfrom
simplify_null_check

Conversation

@Crabcyborg

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Jan 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 27.09%. Comparing base (6a488c0) to head (c38177c).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
classes/helpers/FrmAppHelper.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2752      +/-   ##
============================================
- Coverage     27.09%   27.09%   -0.01%     
+ Complexity     8876     8874       -2     
============================================
  Files           145      145              
  Lines         29809    29815       +6     
============================================
+ Hits           8077     8078       +1     
- Misses        21732    21737       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Crabcyborg
Crabcyborg merged commit b7d3f81 into master Jan 9, 2026
35 of 38 checks passed
@Crabcyborg
Crabcyborg deleted the simplify_null_check branch January 9, 2026 14:47
@coderabbitai

coderabbitai Bot commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Replaced a ternary conditional with null coalescing operator in form option default assignment. The code now uses $values[$opt] = $post_values['options'][$opt] ?? $default; to simplify array access and fallback logic, eliminating unnecessary intermediate checks.

Changes

Cohort / File(s) Summary
Null Coalescing Refactor
classes/helpers/FrmAppHelper.php
Replaced ternary conditional with null coalescing operator for accessing nested form options array with fallback to default value

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a pull request description explaining the motivation for simplifying the null check and any related benefits or considerations.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Simplify null check' directly reflects the main change, which replaces a conditional assignment with a null coalescing operator for cleaner null handling.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @classes/helpers/FrmAppHelper.php:
- Line 3035: Replace the null-coalescing access used to populate $values[$opt]
with the same defensive pattern used elsewhere: check that $post_values is
truthy and that the nested 'options' key for $opt is set before using it,
otherwise fall back to $default; mirror the approach used in
custom_style_value() and FrmFormsHelper.php for $post_values &&
isset($post_values['options'][$var]) to avoid PHP notices.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c24187 and c38177c.

📒 Files selected for processing (1)
  • classes/helpers/FrmAppHelper.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: PHP 7.4 tests in WP 6.9

// phpcs:ignore Universal.Operators.StrictComparisons
if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) {
$values[ $opt ] = $post_values && isset( $post_values['options'][ $opt ] ) ? $post_values['options'][ $opt ] : $default;
$values[ $opt ] = $post_values['options'][ $opt ] ?? $default;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, let's look at the function context around line 3035
sed -n '3029,3051p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 855


🏁 Script executed:

# Search for all calls to fill_form_defaults
rg 'fill_form_defaults' --type php -B 2 -A 2

Repository: Strategy11/formidable-forms

Length of output: 621


🏁 Script executed:

# Check for any validation of $post_values before the problematic line
sed -n '3000,3040p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 1124


🏁 Script executed:

# Find the function that contains the fill_form_defaults call
grep -n 'fill_form_defaults' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 211


🏁 Script executed:

# Get context around the call - look at lines before 3018
sed -n '2950,3025p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 1950


🏁 Script executed:

# Find all calls to fill_form_opts
rg 'fill_form_opts' --type php -B 3 -A 3

Repository: Strategy11/formidable-forms

Length of output: 1046


🏁 Script executed:

# Also search for where $post_values is created/prepared
rg 'post_values\s*=' --type php -B 2 -A 2 | head -100

Repository: Strategy11/formidable-forms

Length of output: 2045


🏁 Script executed:

# Find where post_values is populated with 'options' key
rg "post_values\['options'\]" --type php -B 2 -A 2 | head -80

Repository: Strategy11/formidable-forms

Length of output: 1655


🏁 Script executed:

# Check the function signature and default value of $post_values
sed -n '2840,2860p' classes/helpers/FrmAppHelper.php

Repository: Strategy11/formidable-forms

Length of output: 620


🏁 Script executed:

# Look for any code that explicitly sets $post_values['options']
rg "post_values\s*\[\s*['\"]options['\"]" --type php -B 1 -A 1

Repository: Strategy11/formidable-forms

Length of output: 1241


This change introduces a defensive coding inconsistency.

The null coalescing operator at line 3035 ($post_values['options'][$opt] ?? $default) lacks the defensive checks used elsewhere in the codebase for the same operation. In the same file, custom_style_value() uses $post_values && isset( $post_values['options']['custom_style'] ), and FrmFormsHelper.php uses $post_values && isset( $post_values['options'][ $var ] ) for identical nested array access patterns.

If $post_values is falsy or the 'options' key is missing, this could produce PHP notices in versions prior to PHP 8. Consider adding a defensive check to match the established pattern in the codebase:

$values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default;
🤖 Prompt for AI Agents
In @classes/helpers/FrmAppHelper.php at line 3035, Replace the null-coalescing
access used to populate $values[$opt] with the same defensive pattern used
elsewhere: check that $post_values is truthy and that the nested 'options' key
for $opt is set before using it, otherwise fall back to $default; mirror the
approach used in custom_style_value() and FrmFormsHelper.php for $post_values &&
isset($post_values['options'][$var]) to avoid PHP notices.

stephywells pushed a commit that referenced this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant