Skip to content

Try to add some type comments#2842

Closed
Crabcyborg wants to merge 1 commit into
masterfrom
try_to_add_some_type_comments
Closed

Try to add some type comments#2842
Crabcyborg wants to merge 1 commit into
masterfrom
try_to_add_some_type_comments

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 20, 2026

Summary by CodeRabbit

  • Documentation

    • Enhanced type annotations and documentation across multiple components for improved code clarity.
  • Tests

    • Added new test helper methods for email customization scenarios.
  • Chores

    • Added automated code analysis capability to ensure consistent code quality standards.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 20, 2026

📝 Walkthrough

Walkthrough

This PR adds PHPDoc type annotations (@param, @return) across helper, model, field, and test files to improve code documentation. It introduces a new PHP_CodeSniffer sniff (AddMissingTypeCommentsSniff) that automatically detects and fixes missing type comments in PHP files, and registers it in the ruleset.

Changes

Cohort / File(s) Summary
Helper and Test Documentation Updates
classes/helpers/FrmAppHelper.php, classes/helpers/FrmEntriesListHelper.php, classes/helpers/FrmFormsListHelper.php, classes/helpers/FrmListHelper.php, tests/phpunit/base/FrmUnitTest.php, stripe/helpers/FrmTransLiteListHelper.php
Added @param and @return PHPDoc annotations to methods including allowed_html(), safe_html(), get_columns(), constructors, and test utilities. No functional changes.
Field Model Documentation Updates
classes/models/fields/FrmField*.php (Checkbox, Number, Select, Text, Textarea, Url, UserID)
Added @param and @return PHPDoc annotations to validate(), prepare_import_value(), and prepare_display_value() methods across field classes. No functional changes.
Base Model Documentation
classes/models/FrmOnSubmitAction.php
Added @return array annotation to get_defaults() method. No functional changes.
PHP_CodeSniffer Sniff
phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php
New sniff class that automatically detects and fixes missing or incomplete type annotations in PHP functions. Scans for @param and @return docblock entries, creates or updates docblocks, and applies automated fixes.
Sniff Registration
phpcs-sniffs/Formidable/ruleset.xml
Registered new Formidable.Commenting.AddMissingTypeComments sniff rule.
Test Factory Documentation
tests/phpunit/base/frm_factory.php, tests/phpunit/emails/test_FrmEmail.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/views/shortcodes/test_FrmFieldShortcodes.php
Added @param and @return PHPDoc annotations to test factory methods and test hook handlers (add_to_emails, change_email_subject, send_separate_emails). No functional changes.

Sequence Diagram

sequenceDiagram
    participant PHP_CodeSniffer as PHP_CodeSniffer
    participant Sniff as AddMissingTypeCommentsSniff
    participant Fixer as Fixer
    participant File as PHP File

    PHP_CodeSniffer->>Sniff: register()
    Sniff-->>PHP_CodeSniffer: return [T_FUNCTION]
    
    PHP_CodeSniffer->>Sniff: process(File, stackPtr)
    Sniff->>Sniff: findDocblock()
    Sniff->>Sniff: getFunctionParams()
    Sniff->>Sniff: detectReturnType()
    Sniff->>Sniff: getMissingParamDocs()
    Sniff->>Sniff: getMissingReturn()
    
    alt Missing Type Comments Detected
        Sniff->>Sniff: addMissingDocblock()
        alt No Docblock Exists
            Sniff->>Sniff: createNewDocblock()
            Sniff->>Fixer: addFixableError + auto-fix
            Fixer->>File: insert new docblock
        else Docblock Exists
            Sniff->>Sniff: updateExistingDocblock()
            Sniff->>Fixer: addFixableError + auto-fix
            Fixer->>File: append missing `@param/`@return
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Poem

🐰 Hop along, dear docblocks trace,
Type hints now fill each function space!
A sniff that's wise catches what's amiss,
Comments complete—pure annotation bliss!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and non-descriptive, using generic language ('Try to add some type comments') that doesn't clearly convey what specific type comments are being added or why. Use a more specific and descriptive title such as 'Add PHPDoc type annotations for array parameters and return types' to better summarize the actual changes being made.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 85.37% 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.

@Crabcyborg Crabcyborg closed this Jan 20, 2026
@Crabcyborg Crabcyborg deleted the try_to_add_some_type_comments branch January 20, 2026 13:43
@Crabcyborg Crabcyborg removed this from the 6.28 milestone Jan 20, 2026
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

🤖 Fix all issues with AI agents
In `@classes/models/fields/FrmFieldCheckbox.php`:
- Around line 119-125: The docblock for prepare_import_value in
FrmFieldCheckbox.php lists `@param` array $atts before `@param` mixed $value which
is opposite the method signature prepare_import_value($value, $atts); update the
docblock so parameters are documented in the same order as the signature (first
`@param` mixed $value, then `@param` array $atts) and ensure the types and
descriptions match the actual parameters used by get_multi_opts_for_import.

In `@phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php`:
- Around line 236-290: The hasParamDoc check in hasParamDoc() uses strpos which
can falsely match substrings (e.g., "$args2" matching "$args"); replace the
substring check with a boundary-aware regular expression match: when inspecting
$tokens[$contentToken]['content'] for $paramName, use preg_match with
preg_quote($paramName) and word boundaries (or an appropriate regex like '/\b' .
preg_quote($paramName, '/') . '\b/') to ensure only the exact parameter name is
matched; update hasParamDoc() accordingly so getMissingParamDocs() reliably
detects undocumented params.

In `@tests/phpunit/base/FrmUnitTest.php`:
- Around line 645-648: Update the docblock for run_private_method() to match the
actual signature and types: list the parameters in the correct order (first
$method, then $args) and set their types to reflect usage (e.g. `@param` array
$method and `@param` array $args). Ensure the docblock order and types mirror the
function signature run_private_method($method, $args = array()).

In `@tests/phpunit/emails/test_FrmEmail.php`:
- Around line 496-524: Update the PHPDoc blocks to match each method signature
and include missing return tags: for add_to_emails( $to_emails, $values,
$form_id, $args ) reorder the `@param` lines to `@param` array $to_emails, `@param`
mixed $values, `@param` mixed $form_id, `@param` array $args and add an `@return`
array tag; for change_email_subject( $subject, $args ) ensure `@param` order is
`@param` mixed $subject, `@param` array $args and keep the existing `@return` string
tag; for send_separate_emails( $is_single, $args ) reorder to `@param` mixed
$is_single, `@param` array $args and add an `@return` bool tag so docblocks match
the function signatures and returned types.

In `@tests/phpunit/entries/test_FrmShowEntryShortcode.php`:
- Around line 823-826: Docblock `@param` order is inconsistent with the actual
method signatures; update the `@param` tags to match the argument order for each
affected method (e.g., for two_cell_table_row($field_key, $atts) list `@param`
mixed $field_key before `@param` array $atts, for get_field_html_value($entry,
$field, $atts) list `@param` mixed $entry then `@param` mixed $field then `@param`
array $atts, for expected_array($entry, $atts) list `@param` mixed $entry before
`@param` array $atts, and similarly fix other occurrences noted). Locate the
docblocks for two_cell_table_row, get_field_html_value, expected_array and the
other mentioned blocks and reorder the `@param` tags so they exactly match each
function signature order.
🧹 Nitpick comments (7)
classes/models/fields/FrmFieldUrl.php (2)

68-70: Add a return type for validate().

The method returns the $errors array; documenting it improves clarity and aligns with the PR goal.

Suggested docblock tweak
 /**
  * `@param` array $args
+ * `@return` array
  */
 public function validate( $args ) {

95-98: Document the return type for prepare_display_value().

This method returns the original value or a rendered string; documenting string|array (or mixed) would be clearer.

Suggested docblock tweak
 /**
  * `@param` array $atts
  * `@param` mixed $value
+ * `@return` string|array
  */
 protected function prepare_display_value( $value, $atts ) {
classes/models/fields/FrmFieldSelect.php (1)

94-97: Add a return type for prepare_import_value().

This method returns the processed value; documenting mixed keeps the docblock complete.

Suggested docblock tweak
 /**
  * `@param` array $atts
  * `@param` mixed $value
+ * `@return` mixed
  */
 protected function prepare_import_value( $value, $atts ) {
classes/models/fields/FrmFieldNumber.php (1)

62-65: LGTM!

The @param array $args annotation is correct. Consider adding @return array to document the returned errors array for completeness.

classes/models/fields/FrmFieldText.php (1)

42-54: LGTM!

The @param array $args annotation correctly documents the parameter type.

Consider adding @return array to complete the method documentation, matching the pattern used in FrmFieldUserID::validate().

📝 Optional enhancement
 	/**
 	 * `@param` array $args
+	 *
+	 * `@return` array
 	 */
 	public function validate( $args ) {
phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php (2)

335-398: Drop unused locals to keep PHPMD clean.

addMissingDocblock() and createNewDocblock() initialize locals that aren’t used.

🧹 Suggested cleanup
 private function addMissingDocblock( File $phpcsFile, $stackPtr, $docblock, $missingParamDocs, $missingReturn ) {
-		$tokens = $phpcsFile->getTokens();
-		$fixer  = $phpcsFile->fixer;
-
 		if ( false === $docblock ) {
 			// No existing docblock - create a new one.
 			$this->createNewDocblock( $phpcsFile, $stackPtr, $missingParamDocs, $missingReturn );
@@
 private function createNewDocblock( File $phpcsFile, $stackPtr, $missingParamDocs, $missingReturn ) {
-		$tokens = $phpcsFile->getTokens();
 		$fixer  = $phpcsFile->fixer;

399-461: Remove unused $lastTagPos.

It’s assigned but never read.

🧹 Suggested cleanup
-		$lastParamPos = false;
-		$lastTagPos   = false;
+		$lastParamPos = false;
@@
-			if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG ) {
-				$lastTagPos = $i;
-
-				if ( $tokens[ $i ]['content'] === '@param' ) {
-					$lastParamPos = $i;
-				}
-			}
+			if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG && $tokens[ $i ]['content'] === '@param' ) {
+				$lastParamPos = $i;
+			}

Comment on lines +119 to 125
/**
* @param array $atts
* @param mixed $value
*/
protected function prepare_import_value( $value, $atts ) {
return $this->get_multi_opts_for_import( $value );
}
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

Parameter order in docblock doesn't match method signature.

The method signature is prepare_import_value( $value, $atts ), but the docblock lists @param array $atts before @param mixed $value. The parameters should be documented in the same order as they appear in the method signature.

Suggested fix
 	/**
-	 * `@param` array $atts
 	 * `@param` mixed $value
+	 * `@param` array $atts
 	 */
 	protected function prepare_import_value( $value, $atts ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* @param array $atts
* @param mixed $value
*/
protected function prepare_import_value( $value, $atts ) {
return $this->get_multi_opts_for_import( $value );
}
/**
* `@param` mixed $value
* `@param` array $atts
*/
protected function prepare_import_value( $value, $atts ) {
return $this->get_multi_opts_for_import( $value );
}
🧰 Tools
🪛 PHPMD (2.15.0)

123-123: Avoid unused parameters such as '$atts'. (undefined)

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In `@classes/models/fields/FrmFieldCheckbox.php` around lines 119 - 125, The
docblock for prepare_import_value in FrmFieldCheckbox.php lists `@param` array
$atts before `@param` mixed $value which is opposite the method signature
prepare_import_value($value, $atts); update the docblock so parameters are
documented in the same order as the signature (first `@param` mixed $value, then
`@param` array $atts) and ensure the types and descriptions match the actual
parameters used by get_multi_opts_for_import.

Comment on lines +236 to +290
/**
* Get parameters that need @param array documentation.
*
* @param File $phpcsFile The file being scanned.
* @param false|int $docblock The docblock opener position, or false.
* @param array $params Array of parameter names.
*
* @return array Array of parameter names that need documentation.
*/
private function getMissingParamDocs( File $phpcsFile, $docblock, $params ) {
$needsDocs = array();
$targetNames = array( '$args', '$atts' );

foreach ( $params as $param ) {
if ( ! in_array( $param, $targetNames, true ) ) {
continue;
}

// Check if already documented.
if ( false !== $docblock && $this->hasParamDoc( $phpcsFile, $docblock, $param ) ) {
continue;
}

$needsDocs[ $param ] = 'array';
}

return $needsDocs;
}

/**
* Check if a parameter is documented in the docblock.
*
* @param File $phpcsFile The file being scanned.
* @param int $docblockStart The docblock opener position.
* @param string $paramName The parameter name to check.
*
* @return bool
*/
private function hasParamDoc( File $phpcsFile, $docblockStart, $paramName ) {
$tokens = $phpcsFile->getTokens();
$docblockEnd = $tokens[ $docblockStart ]['comment_closer'];

for ( $i = $docblockStart; $i < $docblockEnd; $i++ ) {
if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG && $tokens[ $i ]['content'] === '@param' ) {
// Check the content after @param for the variable name.
$contentToken = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $i + 1, $docblockEnd );

if ( false !== $contentToken && strpos( $tokens[ $contentToken ]['content'], $paramName ) !== false ) {
return true;
}
}
}

return false;
}
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:

fd -t f "AddMissingTypeCommentsSniff.php" --exec wc -l {}

Repository: Strategy11/formidable-forms

Length of output: 150


🏁 Script executed:

head -n 290 phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php | tail -n 60

Repository: Strategy11/formidable-forms

Length of output: 1804


🏁 Script executed:

sed -n '260,280p' phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php

Repository: Strategy11/formidable-forms

Length of output: 766


🏁 Script executed:

sed -n '230,250p' phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php

Repository: Strategy11/formidable-forms

Length of output: 666


🏁 Script executed:

rg -n "getMissingParamDocs|hasParamDoc" phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php -A 2 -B 2

Repository: Strategy11/formidable-forms

Length of output: 902


Avoid substring matches when detecting documented params.

strpos() can treat @param ... $args2 as matching $args, so missing docs may be skipped. A boundary-aware match avoids that.

🛠️ Proposed fix
-				if ( false !== $contentToken && strpos( $tokens[ $contentToken ]['content'], $paramName ) !== false ) {
+				if ( false !== $contentToken && preg_match( '/\Q' . $paramName . '\E(\s|$)/', $tokens[ $contentToken ]['content'] ) ) {
 					return true;
 				}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Get parameters that need @param array documentation.
*
* @param File $phpcsFile The file being scanned.
* @param false|int $docblock The docblock opener position, or false.
* @param array $params Array of parameter names.
*
* @return array Array of parameter names that need documentation.
*/
private function getMissingParamDocs( File $phpcsFile, $docblock, $params ) {
$needsDocs = array();
$targetNames = array( '$args', '$atts' );
foreach ( $params as $param ) {
if ( ! in_array( $param, $targetNames, true ) ) {
continue;
}
// Check if already documented.
if ( false !== $docblock && $this->hasParamDoc( $phpcsFile, $docblock, $param ) ) {
continue;
}
$needsDocs[ $param ] = 'array';
}
return $needsDocs;
}
/**
* Check if a parameter is documented in the docblock.
*
* @param File $phpcsFile The file being scanned.
* @param int $docblockStart The docblock opener position.
* @param string $paramName The parameter name to check.
*
* @return bool
*/
private function hasParamDoc( File $phpcsFile, $docblockStart, $paramName ) {
$tokens = $phpcsFile->getTokens();
$docblockEnd = $tokens[ $docblockStart ]['comment_closer'];
for ( $i = $docblockStart; $i < $docblockEnd; $i++ ) {
if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG && $tokens[ $i ]['content'] === '@param' ) {
// Check the content after @param for the variable name.
$contentToken = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $i + 1, $docblockEnd );
if ( false !== $contentToken && strpos( $tokens[ $contentToken ]['content'], $paramName ) !== false ) {
return true;
}
}
}
return false;
}
/**
* Get parameters that need `@param` array documentation.
*
* `@param` File $phpcsFile The file being scanned.
* `@param` false|int $docblock The docblock opener position, or false.
* `@param` array $params Array of parameter names.
*
* `@return` array Array of parameter names that need documentation.
*/
private function getMissingParamDocs( File $phpcsFile, $docblock, $params ) {
$needsDocs = array();
$targetNames = array( '$args', '$atts' );
foreach ( $params as $param ) {
if ( ! in_array( $param, $targetNames, true ) ) {
continue;
}
// Check if already documented.
if ( false !== $docblock && $this->hasParamDoc( $phpcsFile, $docblock, $param ) ) {
continue;
}
$needsDocs[ $param ] = 'array';
}
return $needsDocs;
}
/**
* Check if a parameter is documented in the docblock.
*
* `@param` File $phpcsFile The file being scanned.
* `@param` int $docblockStart The docblock opener position.
* `@param` string $paramName The parameter name to check.
*
* `@return` bool
*/
private function hasParamDoc( File $phpcsFile, $docblockStart, $paramName ) {
$tokens = $phpcsFile->getTokens();
$docblockEnd = $tokens[ $docblockStart ]['comment_closer'];
for ( $i = $docblockStart; $i < $docblockEnd; $i++ ) {
if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG && $tokens[ $i ]['content'] === '@param' ) {
// Check the content after `@param` for the variable name.
$contentToken = $phpcsFile->findNext( T_DOC_COMMENT_STRING, $i + 1, $docblockEnd );
if ( false !== $contentToken && preg_match( '/\Q' . $paramName . '\E(\s|$)/', $tokens[ $contentToken ]['content'] ) ) {
return true;
}
}
}
return false;
}
🤖 Prompt for AI Agents
In `@phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingTypeCommentsSniff.php`
around lines 236 - 290, The hasParamDoc check in hasParamDoc() uses strpos which
can falsely match substrings (e.g., "$args2" matching "$args"); replace the
substring check with a boundary-aware regular expression match: when inspecting
$tokens[$contentToken]['content'] for $paramName, use preg_match with
preg_quote($paramName) and word boundaries (or an appropriate regex like '/\b' .
preg_quote($paramName, '/') . '\b/') to ensure only the exact parameter name is
matched; update hasParamDoc() accordingly so getMissingParamDocs() reliably
detects undocumented params.

Comment on lines +645 to +648
/**
* @param array $args
* @param mixed $method
*/
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

Fix docblock parameter order/types for run_private_method().

The docblock lists $args before $method, but the signature is ($method, $args = array()), and $method is expected to be an array.

Suggested docblock fix
 /**
- * `@param` array $args
- * `@param` mixed $method
+ * `@param` array $method
+ * `@param` array $args
+ * `@return` mixed
  */
 protected function run_private_method( $method, $args = array() ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* @param array $args
* @param mixed $method
*/
/**
* `@param` array $method
* `@param` array $args
* `@return` mixed
*/
protected function run_private_method( $method, $args = array() ) {
🤖 Prompt for AI Agents
In `@tests/phpunit/base/FrmUnitTest.php` around lines 645 - 648, Update the
docblock for run_private_method() to match the actual signature and types: list
the parameters in the correct order (first $method, then $args) and set their
types to reflect usage (e.g. `@param` array $method and `@param` array $args).
Ensure the docblock order and types mirror the function signature
run_private_method($method, $args = array()).

Comment on lines +496 to 524
/**
* @param array $args
* @param mixed $to_emails
* @param mixed $values
* @param mixed $form_id
*/
public function add_to_emails( $to_emails, $values, $form_id, $args ) {
$to_emails[] = 'test3@mail.com';
$to_emails[] = '1231231234';
return $to_emails;
}

/**
* @param array $args
* @param mixed $subject
*
* @return string
*/
public function change_email_subject( $subject, $args ) {
return 'New subject';
}

/**
* @param array $args
* @param mixed $is_single
*/
public function send_separate_emails( $is_single, $args ) {
return true;
}
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:

cat -n tests/phpunit/emails/test_FrmEmail.php | sed -n '496,524p'

Repository: Strategy11/formidable-forms

Length of output: 858


Align PHPDoc @param order with method signatures and add missing @return tags.

The @param order in all three methods doesn't match their signatures, which can confuse PHPDoc tooling. Additionally, add_to_emails() and send_separate_emails() are missing @return tags despite returning values.

🛠️ Proposed docblock fix
 /**
- * `@param` array $args
- * `@param` mixed $to_emails
- * `@param` mixed $values
- * `@param` mixed $form_id
+ * `@param` mixed $to_emails
+ * `@param` mixed $values
+ * `@param` mixed $form_id
+ * `@param` array $args
+ *
+ * `@return` array
  */
 public function add_to_emails( $to_emails, $values, $form_id, $args ) {
@@
 /**
- * `@param` array $args
- * `@param` mixed $subject
+ * `@param` mixed $subject
+ * `@param` array $args
  *
  * `@return` string
  */
 public function change_email_subject( $subject, $args ) {
@@
 /**
- * `@param` array $args
- * `@param` mixed $is_single
+ * `@param` mixed $is_single
+ * `@param` array $args
+ *
+ * `@return` bool
  */
 public function send_separate_emails( $is_single, $args ) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* @param array $args
* @param mixed $to_emails
* @param mixed $values
* @param mixed $form_id
*/
public function add_to_emails( $to_emails, $values, $form_id, $args ) {
$to_emails[] = 'test3@mail.com';
$to_emails[] = '1231231234';
return $to_emails;
}
/**
* @param array $args
* @param mixed $subject
*
* @return string
*/
public function change_email_subject( $subject, $args ) {
return 'New subject';
}
/**
* @param array $args
* @param mixed $is_single
*/
public function send_separate_emails( $is_single, $args ) {
return true;
}
/**
* `@param` mixed $to_emails
* `@param` mixed $values
* `@param` mixed $form_id
* `@param` array $args
*
* `@return` array
*/
public function add_to_emails( $to_emails, $values, $form_id, $args ) {
$to_emails[] = 'test3@mail.com';
$to_emails[] = '1231231234';
return $to_emails;
}
/**
* `@param` mixed $subject
* `@param` array $args
*
* `@return` string
*/
public function change_email_subject( $subject, $args ) {
return 'New subject';
}
/**
* `@param` mixed $is_single
* `@param` array $args
*
* `@return` bool
*/
public function send_separate_emails( $is_single, $args ) {
return true;
}
🧰 Tools
🪛 PHPMD (2.15.0)

502-502: Avoid unused parameters such as '$values'. (undefined)

(UnusedFormalParameter)


502-502: Avoid unused parameters such as '$form_id'. (undefined)

(UnusedFormalParameter)


502-502: Avoid unused parameters such as '$args'. (undefined)

(UnusedFormalParameter)


514-514: Avoid unused parameters such as '$subject'. (undefined)

(UnusedFormalParameter)


514-514: Avoid unused parameters such as '$args'. (undefined)

(UnusedFormalParameter)


522-522: Avoid unused parameters such as '$is_single'. (undefined)

(UnusedFormalParameter)


522-522: Avoid unused parameters such as '$args'. (undefined)

(UnusedFormalParameter)

🤖 Prompt for AI Agents
In `@tests/phpunit/emails/test_FrmEmail.php` around lines 496 - 524, Update the
PHPDoc blocks to match each method signature and include missing return tags:
for add_to_emails( $to_emails, $values, $form_id, $args ) reorder the `@param`
lines to `@param` array $to_emails, `@param` mixed $values, `@param` mixed $form_id,
`@param` array $args and add an `@return` array tag; for change_email_subject(
$subject, $args ) ensure `@param` order is `@param` mixed $subject, `@param` array
$args and keep the existing `@return` string tag; for send_separate_emails(
$is_single, $args ) reorder to `@param` mixed $is_single, `@param` array $args and
add an `@return` bool tag so docblocks match the function signatures and returned
types.

Comment on lines +823 to +826
/**
* @param array $atts
* @param mixed $field_key
*/
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

Parameter order in docblocks doesn't match method signatures throughout the file.

Multiple methods have docblock parameters listed in a different order than the method signature. For example:

  • two_cell_table_row( $field_key, $atts ) but docblock lists @param array $atts before @param mixed $field_key
  • get_field_html_value( $entry, $field, $atts ) but docblock lists @param array $atts first
  • expected_array( $entry, $atts ) but docblock lists @param array $atts before @param mixed $entry

The @param tags should be documented in the same order as they appear in the method signature to avoid confusion.

Also applies to: 838-842, 865-868, 883-886, 904-907, 984-988, 994-998, 1170-1173, 1202-1205

🤖 Prompt for AI Agents
In `@tests/phpunit/entries/test_FrmShowEntryShortcode.php` around lines 823 - 826,
Docblock `@param` order is inconsistent with the actual method signatures; update
the `@param` tags to match the argument order for each affected method (e.g., for
two_cell_table_row($field_key, $atts) list `@param` mixed $field_key before `@param`
array $atts, for get_field_html_value($entry, $field, $atts) list `@param` mixed
$entry then `@param` mixed $field then `@param` array $atts, for
expected_array($entry, $atts) list `@param` mixed $entry before `@param` array
$atts, and similarly fix other occurrences noted). Locate the docblocks for
two_cell_table_row, get_field_html_value, expected_array and the other mentioned
blocks and reorder the `@param` tags so they exactly match each function signature
order.

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