Skip to content

New rector rule PreparedValueToEarlyReturnRector#2670

Merged
Crabcyborg merged 16 commits into
masterfrom
new_rector_rule_PreparedValueToEarlyReturnRector
Dec 18, 2025
Merged

New rector rule PreparedValueToEarlyReturnRector#2670
Crabcyborg merged 16 commits into
masterfrom
new_rector_rule_PreparedValueToEarlyReturnRector

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 17, 2025

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 46 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 9ba27ed and b511aa4.

📒 Files selected for processing (1)
  • rector.php (3 hunks)

Walkthrough

This PR contains refactoring changes across the codebase focusing on code simplification: removing intermediate local variables, implementing early returns, and updating Rector and PHPStan configurations. Changes span controller and helper classes, test files, and configuration files, with updated PHPDoc annotations included.

Changes

Cohort / File(s) Summary
Core class simplifications
classes/controllers/FrmAppController.php, classes/helpers/FrmAppHelper.php, classes/helpers/FrmFieldsHelper.php, classes/models/FrmAddon.php, classes/models/FrmCreateFile.php, classes/models/FrmFormApi.php, classes/models/fields/FrmFieldType.php, stripe/helpers/FrmTransLiteAppHelper.php
Remove intermediate local variables and implement early returns. Examples: get_current_page() returns early for view-builder page, get_addon() uses null coalescing operator, get_cache_timeout() returns directly on 429 response, __get() and field_settings_for_type() eliminate temporary variables.
Configuration expansions
rector.php, phpstan.neon
rector.php: Expand rule imports and organize rules across multiple prepared sets and PHP version presets with comprehensive withSkip section. phpstan.neon: Remove strictRules block, expand ignoreErrors message patterns to suppress mixed-type and casting-related errors, remove path-specific ignore blocks.
Test utility refactoring
tests/phpunit/base/FrmUnitTest.php, tests/phpunit/emails/test_FrmEmail.php, tests/phpunit/entries/test_FrmPersonalData.php, tests/phpunit/entries/test_FrmShowEntryShortcode.php, tests/phpunit/fields/test_FrmFieldGridHelper.php.php, tests/phpunit/forms/test_FrmFormsController.php, tests/phpunit/misc/test_FrmAppHelper.php, tests/phpunit/misc/test_FrmCSVExportHelper.php, tests/phpunit/misc/test_FrmOverlayController.php, tests/phpunit/stripe/FrmStrpLiteUnitTest.php, tests/phpunit/stripe/test_FrmTransLiteActionsController.php, tests/phpunit/styles/test_FrmStylesController.php, tests/phpunit/views/shortcodes/test_FrmFieldShortcodes.php
Consolidate return statements to eliminate intermediate variables (e.g., remove $html, $subject, $expected assignments), simplify boolean conditionals, replace __CLASS__ with self::class in callables, remove unused local variables and property mocks. Add public $factory property to test_FrmFormsController. Add PHPDoc for create_entries_for_email.
Documentation updates
stripe/helpers/FrmStrpLiteSubscriptionHelper.php
Update PHPDoc return type annotation for get_plan_from_atts() from string to false|string to reflect actual behavior; method signature unchanged.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Areas requiring extra attention:

  • rector.php: Verify that the expanded set of rules (40+ new imports) are correctly organized and don't introduce unintended transformations across the codebase
  • phpstan.neon: Confirm that removal of strictRules block and expanded ignoreErrors patterns align with project standards and don't mask legitimate type errors
  • FrmFormApi.php, FrmFieldType.php: Verify the refactored return logic in error_for_license() and field_settings_for_type() maintains correct data structure and type expectations
  • Test files: Ensure removed intermediate variables don't affect test assertions or flow (particularly in test_FrmShowEntryShortcode.php with multiple HTML-building methods)

Possibly related PRs

Suggested reviewers

  • lauramekaj1

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, which fails the basic requirement that a description should exist and relate to the changeset. Add a pull request description explaining the purpose, benefits, and scope of the new PreparedValueToEarlyReturnRector rule and its application across the codebase.
Docstring Coverage ⚠️ Warning Docstring coverage is 36.51% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'New rector rule PreparedValueToEarlyReturnRector' directly matches the primary change—introduction of a new Rector rule that refactors code to use early returns instead of prepared values.

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
rector.php (1)

102-133: Syntax error in withPreparedSets() call - pipeline is failing.

The pipeline reports a PHP parse error on line 133. The withPreparedSets() method uses named parameters, not positional boolean arguments. The current syntax with inline comments followed by true/false values is invalid.

The correct syntax for withPreparedSets() uses named parameters:

 	->withPreparedSets(
-		// deadCode
-		true,
-		// codeQuality
-		true,
-		// codingStyle
-		true,
-		// typeDeclarations
-		true,
-		// privatization
-		true,
-		// naming
-		true,
-		// instanceOf
-		true,
-		// earlyReturn
-		true,
-		// strictBooleans
-		true,
-		// carbon
-		true,
-		// rectorPreset
-		true,
-		// phpunitCodeQuality
-		true,
-		// doctrineCodeQuality
-		false,
-		// symfonyCodeQuality
-		false,
-		// symfonyConfigs
-		false,
+		deadCode: true,
+		codeQuality: true,
+		codingStyle: true,
+		typeDeclarations: true,
+		privatization: true,
+		naming: true,
+		instanceOf: true,
+		earlyReturn: true,
+		strictBooleans: true,
+		carbon: true,
+		rectorPreset: true,
+		phpunitCodeQuality: true,
 	)

Note: Parameters like doctrineCodeQuality, symfonyCodeQuality, and symfonyConfigs set to false can typically be omitted since false is usually the default.

🧹 Nitpick comments (2)
classes/models/FrmAddon.php (1)

152-156: get_addon simplification is fine; only edge case is explicit null entries

Using the null coalescing operator to return $plugins[ $plugin_slug ] ?? false is a clean simplification and is equivalent for the expected case where installed addons are non‑null objects/arrays.

The only behavioral change is if a filter intentionally sets $plugins[ $plugin_slug ] to null; that would now be treated as “not found” (false) instead of returning null. If you don’t rely on null as a distinct state anywhere, this is perfectly safe.

If you do care about distinguishing null from false, you could preserve the old semantics with:

public static function get_addon( $plugin_slug ) {
	$plugins = apply_filters( 'frm_installed_addons', array() );

-	return $plugins[ $plugin_slug ] ?? false;
+	if ( array_key_exists( $plugin_slug, $plugins ) ) {
+		return $plugins[ $plugin_slug ];
+	}
+
+	return false;
}
classes/helpers/FrmAppHelper.php (1)

3203-3215: add_time_to_date early-return is correct; condition could be slightly simplified (optional)

The new version still:

  • Falls back to the option value when $time_format is empty.
  • Skips appending a time string when the format is empty or only whitespace.
  • Returns the same formatted " at <time>" suffix as before.

If you want to tighten it further, you could rely solely on the trimmed value:

-	$trimmed_format = trim( $time_format );
-
-	if ( $time_format && ! empty( $trimmed_format ) ) {
+	$trimmed_format = trim( $time_format );
+
+	if ( $trimmed_format !== '' ) {
 		return ' ' . __( 'at', 'formidable' ) . ' ' . self::get_localized_date( $time_format, $date );
 	}

Not required, but slightly reduces duplication in the condition.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b1eddb and f38b5cb.

⛔ Files ignored due to path filters (1)
  • composer.json is excluded by !**/*.json
📒 Files selected for processing (9)
  • classes/controllers/FrmAppController.php (1 hunks)
  • classes/helpers/FrmAppHelper.php (2 hunks)
  • classes/helpers/FrmFieldsHelper.php (1 hunks)
  • classes/models/FrmAddon.php (1 hunks)
  • classes/models/FrmCreateFile.php (1 hunks)
  • classes/models/FrmFormApi.php (2 hunks)
  • classes/models/fields/FrmFieldType.php (2 hunks)
  • rector.php (3 hunks)
  • stripe/helpers/FrmTransLiteAppHelper.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
classes/controllers/FrmAppController.php (1)
classes/helpers/FrmAppHelper.php (3)
  • FrmAppHelper (6-5051)
  • simple_get (806-815)
  • is_view_builder_page (519-535)
classes/helpers/FrmFieldsHelper.php (1)
classes/models/FrmField.php (2)
  • FrmField (6-1619)
  • is_multiple_select (1344-1349)
🪛 GitHub Actions: PHP Syntax Check
rector.php

[error] 133-133: PHP Parse error: syntax error, unexpected ')' in ./rector.php on line 133.

🪛 GitHub Actions: Typo Checks
rector.php

[warning] 205-205: Symplify should be 'Simplify'.


[error] 205-205: typos failed: 'Symplify' should be 'Simplify'. Command './typos .' exited with code 2.

🪛 GitHub Check: Spell Check with Typos
rector.php

[warning] 205-205:
"Symplify" should be "Simplify".

⏰ 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). (1)
  • GitHub Check: PHP 7.4 tests in WP trunk
🔇 Additional comments (10)
stripe/helpers/FrmTransLiteAppHelper.php (1)

382-387: Early-return refactor in get_user_id_for_current_payment looks good

The new implementation is behaviorally equivalent to the prior version and reads more clearly by avoiding the temporary variable. No issues spotted.

classes/models/FrmCreateFile.php (1)

143-148: get_file_contents early return keeps existing behavior

The method now short-circuits when permissions are present and otherwise returns an empty string, matching the prior logic while being simpler. No functional concerns.

classes/helpers/FrmAppHelper.php (1)

437-445: is_formidable_admin refactor preserves behavior and improves readability

Inlining the checks and using early return for the view‑builder case keeps the logic equivalent while making the control flow clearer. No issues found.

classes/controllers/FrmAppController.php (1)

273-282: get_current_page early-return keeps view-builder behavior intact

Returning 'frm_display' immediately when is_view_builder_page() is true, and otherwise falling back to the existing $page/$post_type logic, is behaviorally equivalent to the old implementation and easier to read. Looks good.

classes/helpers/FrmFieldsHelper.php (1)

753-758: Clean early-return refactor.

The simplified control flow correctly handles the select type case with an early return and falls through to return the field type directly for other types. The logic maintains behavioral equivalence with the previous implementation.

classes/models/FrmFormApi.php (2)

371-376: Early return for rate-limited responses.

The refactor correctly short-circuits to return a shorter cache timeout for 429 responses, improving readability while preserving the fallback behavior.


397-402: Simplified error_for_license with direct returns.

Removing the intermediate $errors variable and returning directly from get_error_from_response() is a clean simplification that maintains identical behavior.

classes/models/fields/FrmFieldType.php (2)

122-127: Direct returns in magic getter.

The early return pattern here is cleaner and avoids unnecessary variable assignment when the property exists.


432-437: Simplified field_settings_for_type.

Returning directly instead of assigning to an intermediate variable removes unnecessary complexity while maintaining the same behavior.

rector.php (1)

205-205: False positive from spell checker - SymplifyQuoteEscapeRector is the correct class name.

The static analysis warning about "Symplify" being a typo is incorrect. SymplifyQuoteEscapeRector is the actual class name from the Rector package - it's named after the Symplify organization. This can be safely ignored or added to the typos exclusion list.

Comment thread rector.php Outdated
Comment thread rector.php Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
rector.php (2)

237-240: Duplicate skip rule entry (previously flagged).

ReturnTypeFromStrictConstantReturnRector::class is listed twice (lines 237 and 240). This was flagged in a previous review.


245-247: Duplicate skip rule entry (previously flagged).

MakeInheritedMethodVisibilitySameAsParentRector::class is listed twice (lines 245 and 247). This was flagged in a previous review.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20c8964 and a731030.

📒 Files selected for processing (1)
  • rector.php (3 hunks)
⏰ 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). (1)
  • GitHub Check: Cypress
🔇 Additional comments (2)
rector.php (2)

35-102: Imports look good, but verify PreparedValueToEarlyReturnRector is intentionally active.

The import at line 49 (PreparedValueToEarlyReturnRector) is not added to the skip list, meaning this rule will be active. This aligns with the PR title, so this appears intentional.


119-147: Configuration enables a comprehensive set of Rector rule categories.

The withPreparedSets configuration now enables many rule categories (codeQuality, codingStyle, typeDeclarations, naming, earlyReturn, etc.) with appropriate exclusions for strictBooleans and carbon. The inline comments documenting each parameter are helpful.

Comment thread rector.php
Comment thread rector.php Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 18, 2025

Codecov Report

❌ Patch coverage is 9.09091% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 26.62%. Comparing base (d4269fa) to head (1bf0c73).
⚠️ Report is 6 commits behind head on master.

Files with missing lines Patch % Lines
classes/controllers/FrmAppController.php 0.00% 4 Missing ⚠️
classes/models/FrmFormApi.php 0.00% 4 Missing ⚠️
classes/models/fields/FrmFieldType.php 0.00% 4 Missing ⚠️
classes/helpers/FrmFieldsHelper.php 0.00% 3 Missing ⚠️
classes/helpers/FrmAppHelper.php 50.00% 2 Missing ⚠️
classes/models/FrmCreateFile.php 0.00% 2 Missing ⚠️
classes/models/FrmAddon.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2670   +/-   ##
=========================================
  Coverage     26.62%   26.62%           
+ Complexity     8873     8872    -1     
=========================================
  Files           145      145           
  Lines         29832    29820   -12     
=========================================
- Hits           7942     7940    -2     
+ Misses        21890    21880   -10     

☔ 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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

♻️ Duplicate comments (1)
rector.php (1)

238-241: Remove duplicate skip entry.

ReturnTypeFromStrictConstantReturnRector::class appears twice (lines 238 and 241). This was flagged in previous reviews but remains in the code.

🔎 Apply this diff to remove the duplicate:
 			StringReturnTypeFromStrictScalarReturnsRector::class,
 			ReturnTypeFromStrictConstantReturnRector::class,
 			PostIncDecToPreIncDecRector::class,
 			MultiDirnameRector::class,
-			ReturnTypeFromStrictConstantReturnRector::class,
 			ReturnTypeFromStrictTernaryRector::class,
🧹 Nitpick comments (4)
tests/phpunit/fields/test_FrmFieldGridHelper.php.php (1)

87-89: Good cleanup of unused variable.

The removal of the $quarter_width_field variable assignment is appropriate since the variable is not referenced anywhere in the test method. The field creation is still executed (preserving any setup side effects), but eliminating the unused variable improves code clarity.

If the field created on line 89 is not needed for the test at all (not just the variable reference), consider adding a comment explaining why it's created, or removing the creation entirely if it serves no purpose.

tests/phpunit/fields/test_FrmField.php (1)

8-8: Good addition to formalize the property declaration.

The property is already used throughout the test methods (lines 16, 20, 41), so declaring it explicitly is correct. However, consider adding type information and documentation for better IDE support and maintainability.

🔎 Suggested improvements

If the factory type is known (appears to be a test factory with form and field properties), add type hint and documentation:

+	/**
+	 * @var WP_UnitTest_Factory|null Factory instance for creating test data.
+	 */
-	public $factory;
+	public $factory;

Or if using PHP 7.4+ with proper type:

-	public $factory;
+	public ?WP_UnitTest_Factory $factory;
tests/phpunit/forms/test_FrmFormsController.php (1)

57-57: Consider removing unused function call.

The ob_get_contents() call captures output but the result is immediately discarded. Since ob_end_clean() on line 58 clears the buffer anyway, this call serves no purpose and could be removed entirely.

🔎 Apply this diff to remove the unused call:
 ob_start();
 FrmFormsController::update();
-ob_get_contents();
 ob_end_clean();
tests/phpunit/misc/test_FrmAppHelper.php (1)

7-7: Unused property declaration.

The $factory property is declared but never used in this test file. Consider removing it to avoid clutter.

🔎 Apply this diff to remove the unused property:
-	public $factory;
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1bf0c73 and df7b1dc.

📒 Files selected for processing (42)
  • rector.php (3 hunks)
  • tests/phpunit/base/FrmUnitTest.php (1 hunks)
  • tests/phpunit/bootstrap.php (1 hunks)
  • tests/phpunit/database/test_FrmMigrate.php (1 hunks)
  • tests/phpunit/emails/test_FrmEmail.php (3 hunks)
  • tests/phpunit/entries/test_FrmEntriesAJAXSubmitController.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntriesController.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntriesHelper.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntriesListHelper.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntry.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntryFormatter.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntryMeta.php (1 hunks)
  • tests/phpunit/entries/test_FrmEntryValidate.php (1 hunks)
  • tests/phpunit/entries/test_FrmPersonalData.php (2 hunks)
  • tests/phpunit/entries/test_FrmShowEntryShortcode.php (11 hunks)
  • tests/phpunit/fields/test_FrmField.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldCombo.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldFormHtml.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldGridHelper.php.php (2 hunks)
  • tests/phpunit/fields/test_FrmFieldName.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldType.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldValidate.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldsAjax.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldsController.php (1 hunks)
  • tests/phpunit/fields/test_FrmFieldsHelper.php (1 hunks)
  • tests/phpunit/fields/test_FrmSubmitHelper.php (1 hunks)
  • tests/phpunit/forms/test_FrmForm.php (1 hunks)
  • tests/phpunit/forms/test_FrmFormAction.php (1 hunks)
  • tests/phpunit/forms/test_FrmFormsController.php (3 hunks)
  • tests/phpunit/forms/test_FrmFormsControllerAjax.php (1 hunks)
  • tests/phpunit/forms/test_FrmFormsHelper.php (1 hunks)
  • tests/phpunit/forms/test_FrmOnSubmitAction.php (1 hunks)
  • tests/phpunit/misc/test_FrmAntiSpam.php (1 hunks)
  • tests/phpunit/misc/test_FrmAppHelper.php (4 hunks)
  • tests/phpunit/misc/test_FrmCSVExportHelper.php (2 hunks)
  • tests/phpunit/misc/test_FrmOverlayController.php (0 hunks)
  • tests/phpunit/stripe/FrmStrpLiteUnitTest.php (5 hunks)
  • tests/phpunit/stripe/test_FrmTransLiteActionsController.php (3 hunks)
  • tests/phpunit/styles/test_FrmStylesController.php (1 hunks)
  • tests/phpunit/styles/test_FrmStylesHelper.php (1 hunks)
  • tests/phpunit/test_ajax.php (1 hunks)
  • tests/phpunit/views/shortcodes/test_FrmFieldShortcodes.php (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/phpunit/misc/test_FrmOverlayController.php
✅ Files skipped from review due to trivial changes (2)
  • tests/phpunit/fields/test_FrmFieldFormHtml.php
  • tests/phpunit/fields/test_FrmFieldValidate.php
🧰 Additional context used
🧬 Code graph analysis (3)
tests/phpunit/stripe/test_FrmTransLiteActionsController.php (1)
stripe/controllers/FrmTransLiteActionsController.php (2)
  • FrmTransLiteActionsController (6-646)
  • get_actions_for_form (454-464)
tests/phpunit/styles/test_FrmStylesController.php (1)
tests/phpunit/entries/test_FrmShowEntryShortcode.php (1)
  • get_defaults (798-803)
tests/phpunit/misc/test_FrmAppHelper.php (1)
classes/helpers/FrmAppHelper.php (4)
  • FrmAppHelper (6-5051)
  • get_unique_key (2700-2747)
  • get_ip_address (660-682)
  • clip (1538-1554)
🪛 GitHub Actions: PHPUnit
tests/phpunit/bootstrap.php

[error] 26-26: PHP Warning: require(/tmp/wordpress/src/wp-content/plugins/formidable/tests/phpunit/../../../../tests/phpunit/includes/bootstrap.php): Failed to open stream: No such file or directory in /tmp/wordpress/src/wp-content/plugins/formidable/tests/phpunit/bootstrap.php on line 26. Error in bootstrap script: Failed opening required '/tmp/wordpress/src/wp-content/plugins/formidable/tests/phpunit/../../../../tests/phpunit/includes/bootstrap.php' (include_path='.:/usr/share/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). (1)
  • GitHub Check: Cypress
🔇 Additional comments (47)
tests/phpunit/fields/test_FrmFieldsController.php (1)

8-8: LGTM! Property declaration improves code clarity.

Explicitly declaring the $factory property is good practice, especially since it's already used throughout the test methods. This improves IDE support and makes the code more maintainable.

tests/phpunit/fields/test_FrmFieldGridHelper.php.php (1)

8-8: No issues found with the $factory property declaration.

The explicit declaration of public $factory; is a valid and beneficial practice. It inherits from WP_UnitTestCase (the WordPress unit test base class) and explicit declaration enables IDE autocomplete, static analysis, and type hinting. This pattern is consistently used throughout the test suite.

tests/phpunit/fields/test_FrmField.php (1)

8-8: Remove redundant property declaration.

The $factory property is already properly initialized in the parent class FrmUnitTest::setUp() method (line 53 of tests/phpunit/base/FrmUnitTest.php), which executes before each test method. This declaration is unnecessary and should be removed.

tests/phpunit/fields/test_FrmFieldsHelper.php (1)

10-10: This property declaration is valid and necessary—no conflicts exist with the parent class.

The parent class FrmUnitTest does not declare a $factory property; instead, it dynamically assigns it in the setUp() method (line 53: $this->factory = new FrmUnitTestFactory()). The explicit public $factory; declaration in child test classes is a necessary improvement for static analysis tool compatibility and to prevent PHP 8.2+ dynamic property deprecation warnings.

tests/phpunit/fields/test_FrmFieldsAjax.php (1)

9-9: Verify that exposing $factory as public is intentional.

The $factory property is now explicitly declared as public across multiple test classes in this PR. Since the parent class setUp() already initializes this property, the explicit declaration appears to be for visibility control or IDE support.

Making test fixtures public exposes internal test state that could potentially be modified by external code. If the intent is to provide access for test helpers or utilities, this is acceptable. However, if it's only used within the test class itself, protected visibility would be more appropriate.

Consider whether public visibility is necessary, or if these declarations could be protected instead. Additionally, for better type safety in PHP 7.4+, consider adding type hints (e.g., protected FrmUnitTestFactory $factory;).

This same pattern appears in:

  • tests/phpunit/fields/test_FrmFieldCombo.php
  • tests/phpunit/entries/test_FrmEntryMeta.php
  • tests/phpunit/forms/test_FrmOnSubmitAction.php
  • tests/phpunit/fields/test_FrmFieldType.php
  • tests/phpunit/entries/test_FrmEntry.php
  • tests/phpunit/entries/test_FrmEntryValidate.php
tests/phpunit/base/FrmUnitTest.php (1)

604-604: LGTM: Using canonical function name.

Changed from fputs() to fwrite(). Since fputs() is simply an alias of fwrite(), this change uses the canonical function name without any functional difference. Minor code quality improvement.

tests/phpunit/entries/test_FrmEntriesAJAXSubmitController.php (1)

8-8: LGTM! Good practice to declare the property explicitly.

Making the $factory property explicit improves IDE support and type hinting, even though it's inherited from the parent FrmUnitTest class.

tests/phpunit/database/test_FrmMigrate.php (1)

8-8: LGTM! Consistent property declaration.

Explicitly declaring the $factory property aligns with the broader test suite pattern and improves code clarity.

tests/phpunit/fields/test_FrmFieldName.php (1)

8-8: LGTM! Property declaration follows the established pattern.

tests/phpunit/styles/test_FrmStylesHelper.php (1)

8-8: LGTM! Explicit property declaration improves code maintainability.

tests/phpunit/forms/test_FrmFormsHelper.php (1)

8-8: LGTM! Consistent with the test suite enhancement.

tests/phpunit/entries/test_FrmEntriesListHelper.php (1)

8-8: LGTM! Property declaration aligns with test suite standards.

tests/phpunit/fields/test_FrmSubmitHelper.php (1)

5-5: LGTM! Factory property declared explicitly.

This follows the same pattern as the other test class updates in this PR.

tests/phpunit/entries/test_FrmEntryFormatter.php (1)

8-8: LGTM!

The explicit $factory property declaration aligns with the broader pattern across the test suite to make factory access explicit.

tests/phpunit/emails/test_FrmEmail.php (3)

9-9: LGTM!

The explicit $factory property declaration is consistent with the broader test suite pattern.


433-435: LGTM!

Direct return simplifies the method without changing behavior.


505-507: LGTM!

Direct return of the literal string is cleaner than assigning to an intermediate variable.

tests/phpunit/views/shortcodes/test_FrmFieldShortcodes.php (2)

10-10: LGTM!

The explicit $factory property declaration follows the established pattern.


74-88: LGTM!

Directly returning the array eliminates the unnecessary intermediate $expected variable.

tests/phpunit/test_ajax.php (1)

7-7: LGTM!

The explicit $factory property declaration is consistent with the test suite pattern.

tests/phpunit/stripe/test_FrmTransLiteActionsController.php (2)

8-8: LGTM!

The explicit $factory property declaration follows the established pattern.


18-32: LGTM!

Removing the unused $action_id assignment is a valid cleanup. The test retrieves the action via get_actions_for_form() on line 31 anyway.

tests/phpunit/misc/test_FrmCSVExportHelper.php (2)

7-7: LGTM!

The explicit $factory property declaration follows the established pattern.


98-106: LGTM!

Removing the unused $embed_field assignment is a valid cleanup. The embed field is created for its side effect (being stored in the database), and the returned object isn't needed.

tests/phpunit/stripe/FrmStrpLiteUnitTest.php (5)

5-5: LGTM!

The explicit $factory property declaration follows the established pattern.


237-239: LGTM!

Using the null coalescing operator for a direct return is cleaner than the previous intermediate variable approach.


291-296: LGTM!

Inlining the get_stripe_account_id_details() call directly as the parameter is a valid simplification.


301-310: LGTM!

Directly returning the array eliminates the unnecessary $new_charge intermediate variable.


451-455: LGTM!

The get_customer() call is invoked for its side effect (ensuring a customer exists). Removing the unused $customer assignment is correct.

tests/phpunit/entries/test_FrmShowEntryShortcode.php (4)

13-13: LGTM! Explicit property declaration improves clarity.

Making the $factory property explicitly public is good practice and improves IDE support and code clarity.


758-758: LGTM! Clean refactor to early return.

The direct return eliminates unnecessary intermediate variables and improves readability.


899-905: The change from strict equality to truthy evaluation is safe.

The $include variable is guaranteed to always contain a boolean value. All assignments are either boolean literals (true/false) or results of in_array() with strict comparison, which always returns a boolean. The is_self_or_parent_in_array() method returns in_array(..., true), ensuring a boolean result. Using loose evaluation if ( $include ) instead of if ( $include === true ) is actually more idiomatic PHP and poses no risk of unexpected behavior from truthy non-boolean values.


30-34: No issues found. The parent class FrmUnitTest does not have a constructor with initialization logic—all setup occurs in the setUp() method, which is automatically invoked by PHPUnit and does not require an explicit call in the child class's constructor.

tests/phpunit/entries/test_FrmEntriesHelper.php (1)

8-8: LGTM! Explicit property declaration.

Consistent with the pattern across test files to make the $factory property explicitly public.

tests/phpunit/forms/test_FrmFormAction.php (1)

8-8: LGTM! Consistent property declaration.

Aligns with the project-wide pattern of explicitly declaring the $factory property.

tests/phpunit/forms/test_FrmForm.php (1)

8-8: LGTM! Property declaration for consistency.

Consistent with other test classes in this PR.

tests/phpunit/entries/test_FrmEntriesController.php (1)

8-8: LGTM! Explicit factory property.

Good practice for test fixture management.

tests/phpunit/forms/test_FrmFormsControllerAjax.php (1)

8-8: LGTM! Property declaration pattern.

Maintains consistency across test suite.

tests/phpunit/entries/test_FrmPersonalData.php (2)

8-8: LGTM! Explicit property for test factory.

Consistent with the broader test suite improvements.


65-70: LGTM! Documentation improvement.

Adding PHPDoc improves code documentation and IDE support.

tests/phpunit/forms/test_FrmFormsController.php (2)

9-9: LGTM! Consistent property declaration.

Aligns with the test factory pattern across the codebase.


115-115: LGTM! Simplified assignment.

The direct assignment is clearer than a conditional and preserves the same boolean result.

tests/phpunit/misc/test_FrmAppHelper.php (2)

570-570: LGTM: Modern class reference syntax.

The refactor from __CLASS__ to self::class improves consistency and follows modern PHP best practices.

Also applies to: 578-578


700-700: LGTM: Consistent class reference syntax.

The refactor from __CLASS__ to self::class for building callable strings is consistent with modern PHP practices and matches the changes elsewhere in the file.

Also applies to: 706-706

rector.php (3)

35-102: LGTM: Imports align with configuration.

The new imports support the expanded Rector configuration below. Notably, PreparedValueToEarlyReturnRector (line 49) is imported but not included in the skip array, meaning it will be enabled as intended per the PR objectives.


112-112: No action needed—including the tests directory in Rector paths is standard practice and ensures consistent code quality across the entire project, including test code.


120-148: This is a new Rector configuration file, not modifications to an existing configuration.

The file introduces a new rector.php with multiple prepared sets enabled (codeQuality, codingStyle, typeDeclarations, typeDeclarationDocblocks, privatization, naming, instanceOf, earlyReturn, rectorPreset, phpunitCodeQuality) along with an extensive skip list of 64+ specific rules (lines 169-274). This is a valid approach that enables broad rule sets while selectively excluding problematic rules. The configuration should be tested to ensure it produces the desired refactoring behavior.

Likely an incorrect or invalid review comment.

Comment thread rector.php
Comment thread tests/phpunit/bootstrap.php Outdated
Comment thread tests/phpunit/misc/test_FrmAntiSpam.php Outdated
Comment thread tests/phpunit/misc/test_FrmAppHelper.php Outdated
Comment thread tests/phpunit/styles/test_FrmStylesController.php Outdated
@Crabcyborg Crabcyborg merged commit 71c089a into master Dec 18, 2025
15 of 16 checks passed
@Crabcyborg Crabcyborg deleted the new_rector_rule_PreparedValueToEarlyReturnRector branch December 18, 2025 02:31
@coderabbitai coderabbitai Bot mentioned this pull request Dec 22, 2025
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