Skip to content

Add missing block comments and type comments#2868

Merged
Crabcyborg merged 6 commits into
masterfrom
add_missing_block_comments_and_type_comments
Jan 22, 2026
Merged

Add missing block comments and type comments#2868
Crabcyborg merged 6 commits into
masterfrom
add_missing_block_comments_and_type_comments

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 22, 2026

This requires turning off a php cs fixer rule for now so it doesn't add a ton of mixed param comments, messing up Psalm and PHPStan.

Summary by CodeRabbit

  • New Features

    • Added a new PHP_CodeSniffer sniff to automatically detect and suggest missing docblock annotations for functions and methods.
  • Documentation

    • Enhanced code documentation with comprehensive PHPDoc blocks across multiple classes, including parameter and return type annotations.
  • Chores

    • Updated PHP-CS-Fixer configuration and integrated the new sniff into the coding standards ruleset.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 22, 2026

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 28 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.

📝 Walkthrough

Walkthrough

This PR introduces an automated PHP_CodeSniffer sniff for generating PHPDoc docblocks with type annotations, disables the conflicting phpdoc_add_missing_param_annotation rule, and adds comprehensive documentation blocks across helper, model, field, and test classes.

Changes

Cohort / File(s) Summary
Configuration & Tooling
.php-cs-fixer.php, phpcs-sniffs/Formidable/ruleset.xml
Removed phpdoc_add_missing_param_annotation rule and registered new AddMissingDocblockSniff in ruleset
New CodeSniffer Sniff
phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingDocblockSniff.php
Implemented custom sniff (+717 lines) that auto-generates or augments PHPDoc blocks with constrained @param and @return annotations, detecting types via parameter naming conventions and code usage patterns
Helper Classes
classes/helpers/FrmAppHelper.php, classes/helpers/FrmEntriesListHelper.php, classes/helpers/FrmFormsListHelper.php, classes/helpers/FrmListHelper.php, stripe/helpers/FrmTransLiteListHelper.php
Added @param and @return docblock annotations to constructors and public methods
Model Classes
classes/models/FrmMigrate.php, classes/models/FrmOnSubmitAction.php, classes/models/FrmSpamCheckUseWPComments.php, classes/models/FrmSpamCheckWPDisallowedWords.php
Added @return type docblock annotations to public methods
Field Model Classes
classes/models/fields/FrmFieldNumber.php, classes/models/fields/FrmFieldText.php, classes/models/fields/FrmFieldUrl.php, classes/models/fields/FrmFieldUserID.php
Added @param and @return docblock annotations to validate() and related methods
Test Base & Utilities
tests/phpunit/base/FrmUnitTest.php, tests/phpunit/base/frm_factory.php
Added docblock annotations to test helper methods; enhanced run_private_method() to return reflected method result
Test Files
tests/phpunit/emails/test_FrmEmail.php, tests/phpunit/entries/test_FrmPersonalData.php, tests/phpunit/entries/test_FrmShowEntryShortcode.php, tests/phpunit/entries/test_FrmTableHTMLGenerator.php, tests/phpunit/fields/test_FrmFieldValidate.php, tests/phpunit/misc/test_FrmAppHelper.php, tests/phpunit/misc/test_FrmCurrencyHelper.php, tests/phpunit/misc/test_FrmSpamCheckWPDisallowedWords.php, tests/phpunit/views/shortcodes/test_FrmFieldShortcodes.php
Added @param and @return docblock annotations across protected and public test methods

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐰 A sniff that understands what types should be,
Auto-docblocks for all, both you and me!
Parameters typed, returns made clear,
Our codebase shines, documentation sincere!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding PHPDoc block comments and type annotations throughout the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 86.84% which is sufficient. The required threshold is 80.00%.

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


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: 3

Caution

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

⚠️ Outside diff range comments (1)
classes/models/FrmEmailMonthly.php (1)

27-38: Fix return annotation to match the inherited signature (Psalm failing).

Line 30 documents @return bool, but the method returns false or parent::get_content_args() (array|false). This mismatches the parent signature and is already breaking Psalm. Update the docblock to reflect the actual return type.

✅ Suggested fix
-	 * `@return` bool
+	 * `@return` array|false
🤖 Fix all issues with AI agents
In `@classes/models/FrmEmailYearly.php`:
- Around line 28-30: The docblock for get_content_args() incorrectly declares
"@return bool"; update it to match the parent return type (array|false) so the
method signature and PHPDoc align with parent::get_content_args(); change the
`@return` annotation to "array|false" on the get_content_args() docblock in class
FrmEmailYearly.

In `@phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingDocblockSniff.php`:
- Around line 214-271: isUsedAsArray currently scans the whole function body and
can mis-detect array usage from nested closures/functions; update isUsedAsArray
(used by getCertainParamTypes) to ignore tokens inside nested scopes by skipping
over any inner scope token (e.g., T_FUNCTION, T_CLOSURE, T_CLASS, T_ANON_CLASS)
encountered between $scopeOpener and $scopeCloser: when you find one, advance
the loop index to that token's ['scope_closer'] so variables inside that nested
scope are not considered, then continue the search for the target $varName
followed by T_OPEN_SQUARE_BRACKET.

In `@tests/phpunit/misc/test_FrmSpamCheckWPDisallowedWords.php`:
- Around line 63-65: The docblock in
tests/phpunit/misc/test_FrmSpamCheckWPDisallowedWords.php that currently
declares "@return bool" is incorrect because the method actually returns the
string values 'blacklist_keys' or 'disallowed_keys'; update the `@return`
annotation to "@return string" in that method's docblock so it correctly
reflects the return type.
🧹 Nitpick comments (4)
classes/models/fields/FrmFieldSelect.php (1)

94-97: Consider documenting the $value parameter as well.

The docblock only documents $atts but the method also has a $value parameter. For completeness, consider adding documentation for both parameters.

♻️ Suggested improvement
 	/**
+	 * `@param` mixed $value
 	 * `@param` array $atts
 	 */
 	protected function prepare_import_value( $value, $atts ) {
tests/phpunit/base/FrmUnitTest.php (1)

479-486: Consider using a union type for the $type parameter.

The @param array $type annotation is partially accurate, but the method also accepts a string since it casts the parameter to an array on line 486 with $type = (array) $type;. For completeness, consider using @param string|array $type.

📝 Suggested documentation improvement
 	/**
-	 * `@param` array $type
+	 * `@param` string|array $type
 	 */
 	public static function generate_xml( $type, $xml_args ) {
phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingDocblockSniff.php (2)

98-101: Remove unused local in processMissingAnnotations.

$tokens is never referenced.

♻️ Proposed cleanup
-		$tokens = $phpcsFile->getTokens();
-
 		$params         = $this->getParameters( $phpcsFile, $stackPtr );

540-572: Clean up unused locals in addMissingAnnotations.

$lastContentLine, $insertBefore, and $lastTag are unused; removing them simplifies the method.

♻️ Proposed cleanup
-		$lastContentLine = $tokens[ $closer ]['line'] - 1;
-
 		// Get indentation from docblock opener.
 		$indent = '';
 		$lineStart = $docblock;
@@
-		// Find position to insert (before the closing tag).
-		$insertBefore = $closer;
-
-		// Look for existing `@return` or `@param` to insert after.
-		$lastTag = null;
-
-		for ( $i = $docblock; $i < $closer; $i++ ) {
-			if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG ) {
-				$lastTag = $i;
-			}
-		}
-
 		$fixer->beginChangeset();

Comment thread classes/models/FrmEmailYearly.php Outdated
Comment thread tests/phpunit/misc/test_FrmSpamCheckWPDisallowedWords.php
@Crabcyborg Crabcyborg merged commit 23e52a1 into master Jan 22, 2026
15 of 16 checks passed
@Crabcyborg Crabcyborg deleted the add_missing_block_comments_and_type_comments branch January 22, 2026 21:52
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…nd_type_comments

Add missing block comments and type comments
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