Skip to content

Add and fix return and param types where missing#1732

Open
pattonwebz wants to merge 5 commits into
developfrom
william/no-issue/add-and-fix-return-and-param-types-where-missing
Open

Add and fix return and param types where missing#1732
pattonwebz wants to merge 5 commits into
developfrom
william/no-issue/add-and-fix-return-and-param-types-where-missing

Conversation

@pattonwebz

@pattonwebz pattonwebz commented May 29, 2026

Copy link
Copy Markdown
Member

This pull request primarily improves code documentation and type safety throughout the codebase. The most significant changes are the addition of explicit @return annotations in PHPDoc blocks, updates to parameter and return types for better accuracy, and minor improvements to script enqueuing. These changes enhance code readability, maintainability, and developer experience, especially when using IDEs or static analysis tools.

Documentation and Type Hinting Improvements:

  • Added explicit @return annotations (such as @return void, @return array, @return bool, @return string) to PHPDoc blocks for many public methods and functions across multiple files, clarifying expected return types and improving code documentation. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]

  • Improved parameter and return type documentation in helper and query classes, such as changing parameter types from int to int|float and specifying accurate return types (e.g., string|false, string|int|float). [1] [2] [3] [4]

Script and Style Enqueuing:

  • Updated calls to wp_enqueue_script and wp_enqueue_style in several places to use an empty array ([]) instead of false for the dependencies argument, aligning with best practices and preventing potential warnings. [1] [2]

Bug Fixes and Minor Adjustments:

  • Fixed a potential bug by ensuring the third parameter passed to edac_get_upcoming_meetups_html is a string instead of an integer.

These changes are mostly non-functional but are important for long-term maintainability and code quality.

Fixes: #393

Summary by CodeRabbit

  • Bug Fixes

    • Fixed script and style dependency handling for proper asset loading.
  • Refactor

    • Improved data sanitization consistency for form submissions.
    • Enhanced type annotations and casting for numerical calculations.
    • Updated PHPDoc documentation across codebase for better code clarity.

Review Change Stack

Copilot AI review requested due to automatic review settings May 29, 2026 18:19
@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR standardizes code documentation and hygiene across the codebase by adding ~50 missing @return void PHPDoc annotations to methods, correcting parameter and return type documentation, standardizing WordPress enqueue dependency arguments from false to empty arrays, and refactoring settings sanitization callbacks to use structured argument arrays.

Changes

Documentation and code hygiene improvements

Layer / File(s) Summary
Interface and base class documentation
includes/classes/Fixes/FixInterface.php, admin/AdminPage/PageInterface.php
FixInterface and PageInterface now document @return void for register(), run(), add_page(), and render_page() methods.
Fix implementation documentation
includes/classes/Fixes/Fix/*.php, includes/classes/Fixes/FixesManager.php
14 Fix classes and FixesManager consistently declare @return void for all register(), run(), and callback methods.
Skip link fix logic adjustment
includes/classes/Fixes/Fix/SkipLinkFix.php
Early exit changed from return null; to return; and $targets array explicitly initialized before operations.
Admin page and panel documentation
admin/AdminPage/FixesPage.php, admin/AdminPage/FixesSettingType/*, admin/AdminPage/PageInterface.php
FixesPage methods and setting type callbacks now include @return void documentation.
Admin class documentation and enqueue standardization
admin/class-activation-redirect.php, admin/class-admin-footer-text.php, admin/class-enqueue-admin.php, admin/class-frontend-highlight.php, admin/class-orphaned-issues-cleanup.php, admin/class-update-database.php, includes/classes/MyDot/Connector.php
Admin classes receive @return void documentation; edac-editor-app script dependencies standardized from false to [].
Helper function type documentation
admin/class-helpers.php, admin/class-issues-query.php, admin/class-settings.php
Parameter and return types broadened in documentation to reflect actual usage (int|float, int|string); $flags parameter corrected from string to int; @var corrected to @return.
Frontend and widget enqueue documentation
includes/classes/class-enqueue-frontend.php, admin/class-widgets.php
Enqueue_Frontend constructor and frontend highlighter app dependencies standardized to []; meetups argument passed as string '4' instead of integer.
Core class documentation standardization
includes/classes/class-accessibility-statement.php, includes/classes/class-lazyload-filter.php, includes/classes/class-simplified-summary.php, includes/classes/class-rest-api.php, admin/opt-in/class-email-opt-in.php
Multiple core classes document @return void and @return bool; REST request parameters qualified with \WP_REST_Request namespace.
Numeric return type refinements
includes/helper-functions.php, includes/classes/class-summary-generator.php
edac_get_issue_density() returns (float) instead of uncast result; calculate_passed_tests() casts to integer; density and summary methods document @return void.
Settings registration and sanitization refactoring
includes/options-page.php
register_setting() calls refactored to use ['sanitize_callback' => ...] arrays; simplified summary and accessibility policy sanitizers explicitly return '' for invalid input; 15+ option-rendering callbacks receive @return void documentation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested labels

codex

Poem

🐰 Doc blocks bloom with caring annotations,
@return void now marks the declarations,
Type hints grow precise, no more confusion,
Empty arrays replace false's delusion,
Code reads cleaner—a hygiene vacation!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Minor out-of-scope functional changes detected: dependency argument conversions (false to []), edac_get_upcoming_meetups_html string casting, and type casting in Summary_Generator are beyond pure documentation fixes. These functional changes should be separated into a distinct PR or clearly justified as necessary for the documentation improvements. Verify that dependency changes and type casting modifications align with issue #393 requirements.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding and fixing missing return and parameter type annotations across the codebase.
Linked Issues check ✅ Passed The PR comprehensively addresses issue #393 by adding missing @return and @param type annotations across numerous public methods/functions, correcting documented return types (e.g., string to int|float), and improving documentation accuracy.
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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch william/no-issue/add-and-fix-return-and-param-types-where-missing

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request focuses on improving type safety and documentation across the codebase by adding return types to docblocks, modernizing register_setting calls, and ensuring correct type casting. Key improvements are suggested for includes/options-page.php: first, the edac_sanitize_accessibility_policy_page function should support numeric page IDs by checking if the input is numeric before applying esc_url(); second, the sanitization functions for position and prompt should return their respective default values instead of an empty string when encountering invalid inputs to prevent bypassing default option fallbacks in the settings UI.

Comment thread includes/options-page.php
Comment on lines 834 to +837
if ( $page ) {
return esc_url( $page );
}
return '';

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.

high

The edac_sanitize_accessibility_policy_page function sanitizes the input using esc_url(). However, the accessibility policy page option can also be stored as a numeric page ID (as seen in edac_accessibility_policy_page_cb(), which checks is_numeric( $policy_page )). Running esc_url() on a numeric string like '42' will return an empty string, thereby breaking the option when a page ID is selected.

To support both numeric page IDs and URLs, check if the input is numeric and sanitize accordingly using absint() and esc_url_raw().

	if ( $page ) {
		return is_numeric( $page ) ? absint( $page ) : esc_url_raw( $page );
	}
	return '';

Comment thread includes/options-page.php
Comment on lines 601 to +604
if ( in_array( $position, [ 'before', 'after', 'none' ], true ) ) {
return $position;
}
return '';

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.

medium

Returning an empty string '' when the position is invalid will cause an empty string to be saved in the database. This bypasses the default value fallback of get_option() and results in none of the radio buttons being selected in the settings UI.

Instead of returning '', it is safer to return the default value 'after' to ensure the UI remains consistent.

	if ( in_array( $position, [ 'before', 'after', 'none' ], true ) ) {
		return $position;
	}
	return 'after';

Comment thread includes/options-page.php
Comment on lines 657 to +660
if ( in_array( $prompt, [ 'when required', 'always', 'none' ], true ) ) {
return $prompt;
}
return '';

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.

medium

Returning an empty string '' when the prompt is invalid will cause an empty string to be saved in the database. This bypasses the default value fallback of get_option() and results in none of the radio buttons being selected in the settings UI.

Instead of returning '', it is safer to return the default value 'when required' to ensure the UI remains consistent.

	if ( in_array( $prompt, [ 'when required', 'always', 'none' ], true ) ) {
		return $prompt;
	}
	return 'when required';

Copilot AI 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.

Copilot reviewed 34 out of 34 changed files in this pull request and generated 4 comments.

* @param array $filter [post_types, rule_types, rule_slugs].
* @param integer $record_limit Max number of records we'll query.
* @param string $flags Flag used to determine how ignored issues sould be handled.
* @param int $flags Flag used to determine how ignored issues sould be handled.
Comment on lines 91 to +93
* Run the fix for adding the comment and search form labels.
*
* @return void
Comment on lines 89 to +91
* Run the fix for adding the comment and search form labels.
*
* @return void
Comment on lines 116 to +118
* Run the fix for adding the comment and search form labels.
*
* @return void

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

Caution

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

⚠️ Outside diff range comments (3)
includes/helper-functions.php (1)

434-436: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Keep edac_get_issue_density() return type consistently float.

With @return float and the cast on Line 449, the early exit on Line 435 should return a float literal too to avoid mixed return types.

Suggested fix
 	if ( $element_count < 1 || $content_length < 1 ) {
-		return 0;
+		return 0.0;
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@includes/helper-functions.php` around lines 434 - 436, The early return in
edac_get_issue_density() returns integer 0 causing mixed return types; change
that early exit to return a float literal (e.g., 0.0) so the function always
returns float (keep the existing float cast at the final return intact).
admin/class-helpers.php (2)

65-89: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update the @return type for Helpers::format_percentage().
The unit tests expect numeric inputs to always return a string containing the %, and non-numeric inputs to return the value unchanged (e.g., 'N/A'), so the current @return string|int|float docblock doesn’t match the actual behavior—document the return as string (or explicitly note that non-numeric inputs are returned as-is).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@admin/class-helpers.php` around lines 65 - 89, Update the PHPDoc for
Helpers::format_percentage() to reflect actual behavior: change the `@return` from
"string|int|float" to "string" (and note in the docblock that non-numeric inputs
are returned unchanged), so that numeric inputs always document returning a
percent string (e.g., "12.34%") while non-numeric inputs are returned as-is.

40-60: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix @return PHPDoc for Helpers::format_number() to match implementation
format_number() returns the original $number unchanged when it’s not numeric (return $number;), but the docblock says @return string|false. Update the @return annotation to include the non-numeric passthrough type(s) (or change the function to only accept numeric inputs).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@admin/class-helpers.php` around lines 40 - 60, The PHPDoc for
Helpers::format_number() is incorrect: the function can return the original
non-numeric $number as-is or a formatted string (and NumberFormatter::format()
can return false on failure). Update the `@return` annotation for format_number()
to reflect the actual possible types (e.g. string|int|float|false|mixed) so it
documents both formatted string/false and the passthrough non-numeric value.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@admin/class-helpers.php`:
- Around line 65-89: Update the PHPDoc for Helpers::format_percentage() to
reflect actual behavior: change the `@return` from "string|int|float" to "string"
(and note in the docblock that non-numeric inputs are returned unchanged), so
that numeric inputs always document returning a percent string (e.g., "12.34%")
while non-numeric inputs are returned as-is.
- Around line 40-60: The PHPDoc for Helpers::format_number() is incorrect: the
function can return the original non-numeric $number as-is or a formatted string
(and NumberFormatter::format() can return false on failure). Update the `@return`
annotation for format_number() to reflect the actual possible types (e.g.
string|int|float|false|mixed) so it documents both formatted string/false and
the passthrough non-numeric value.

In `@includes/helper-functions.php`:
- Around line 434-436: The early return in edac_get_issue_density() returns
integer 0 causing mixed return types; change that early exit to return a float
literal (e.g., 0.0) so the function always returns float (keep the existing
float cast at the final return intact).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 08d33c14-1c6e-4a64-89f9-911b345c0379

📥 Commits

Reviewing files that changed from the base of the PR and between 6986dfa and 0e9c2ec.

📒 Files selected for processing (34)
  • admin/AdminPage/FixesPage.php
  • admin/AdminPage/FixesSettingType/Checkbox.php
  • admin/AdminPage/FixesSettingType/Text.php
  • admin/AdminPage/PageInterface.php
  • admin/class-activation-redirect.php
  • admin/class-admin-footer-text.php
  • admin/class-enqueue-admin.php
  • admin/class-frontend-highlight.php
  • admin/class-helpers.php
  • admin/class-issues-query.php
  • admin/class-orphaned-issues-cleanup.php
  • admin/class-settings.php
  • admin/class-update-database.php
  • admin/class-widgets.php
  • admin/opt-in/class-email-opt-in.php
  • includes/classes/Fixes/Fix/AddFileSizeAndTypeToLinkedFilesFix.php
  • includes/classes/Fixes/Fix/AddLabelToUnlabelledFormFieldsFix.php
  • includes/classes/Fixes/Fix/AddNewWindowWarningFix.php
  • includes/classes/Fixes/Fix/BlockPDFUploadsFix.php
  • includes/classes/Fixes/Fix/CommentSearchLabelFix.php
  • includes/classes/Fixes/Fix/MetaViewportScalableFix.php
  • includes/classes/Fixes/Fix/PreventLinksOpeningNewWindowFix.php
  • includes/classes/Fixes/Fix/SkipLinkFix.php
  • includes/classes/Fixes/FixInterface.php
  • includes/classes/Fixes/FixesManager.php
  • includes/classes/MyDot/Connector.php
  • includes/classes/class-accessibility-statement.php
  • includes/classes/class-enqueue-frontend.php
  • includes/classes/class-lazyload-filter.php
  • includes/classes/class-rest-api.php
  • includes/classes/class-simplified-summary.php
  • includes/classes/class-summary-generator.php
  • includes/helper-functions.php
  • includes/options-page.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve inline documentation

2 participants