Skip to content

Updated: passed test percentage logic to include scannable post types and handle cases with no posts scanned. - #1291

Merged
SteveJonesDev merged 2 commits into
developfrom
steve/no-issue/passed-test-percentage-logic
Dec 16, 2025
Merged

Updated: passed test percentage logic to include scannable post types and handle cases with no posts scanned.#1291
SteveJonesDev merged 2 commits into
developfrom
steve/no-issue/passed-test-percentage-logic

Conversation

@SteveJonesDev

@SteveJonesDev SteveJonesDev commented Dec 2, 2025

Copy link
Copy Markdown
Member

This pull request updates the scan statistics logic in admin/class-scans-stats.php to better handle scannable post types and calculation of passed percentage. The main improvements focus on ensuring that only relevant post types are considered and that the passed percentage is calculated more accurately.

Scan statistics improvements:

  • The Issues_Query initialization now includes a post_types parameter set to the result of Settings::get_scannable_post_types(), ensuring that only scannable post types are queried.
  • The calculation of passed_percentage now sets it to 'N/A' by default and only computes a percentage if there are scannable post types and scanned posts, preventing misleading statistics when no relevant data is present.
Screenshot 2025-12-02 at 5 03 53 PM Screenshot 2025-12-02 at 5 03 59 PM

Fixes: PRO-265

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Scan statistics now correctly filter results to scannable post types only
    • Pass percentage displays 'N/A' when insufficient scan data is available, instead of potentially misleading values
    • Improved accuracy of pass percentage calculations

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

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @SteveJonesDev, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the scan statistics logic to enhance the accuracy and relevance of the displayed data. It ensures that issue queries are limited to only scannable post types and introduces a more robust calculation for the "passed percentage," preventing its display when no meaningful data is available. This leads to more reliable and contextually appropriate scan reports.

Highlights

  • Improved Issue Query Filtering: The Issues_Query initialization now explicitly filters issues by including only scannable post types, ensuring that statistics are based on relevant content and removing the previous FLAG_INCLUDE_ALL_POST_TYPES.
  • Robust Passed Percentage Calculation: The passed_percentage calculation has been enhanced to default to 'N/A' and will only compute a percentage if there are both scannable post types configured and posts have actually been scanned, preventing misleading statistics when no relevant data is present.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai

coderabbitai Bot commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The summary() method in admin/class-scans-stats.php now retrieves post types using Settings::get_scannable_post_types() instead of a constant flag, and changes passed_percentage default from 100 to 'N/A', computing it only when scannable post types exist, posts scanned exceed zero, and tests are present.

Changes

Cohort / File(s) Change Summary
Statistics calculation refinement
admin/class-scans-stats.php
Modified summary() method: replaced FLAG_INCLUDE_ALL_POST_TYPES constant with Settings::get_scannable_post_types() for post type filtering; changed default passed_percentage from 100 to 'N/A'; added conditional logic to compute percentage only when scannable post types, scanned posts > 0, and tests_count > 0 exist; percentage calculation remains rules_passed/rule_count ratio rounded to 2 decimals

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Key area: Verify that Settings::get_scannable_post_types() is the correct method to replace FLAG_INCLUDE_ALL_POST_TYPES and returns compatible data
  • Confirm the conditions for when passed_percentage should remain 'N/A' vs. when it should be computed are logically sound
  • Review implications of changing default from 100 to 'N/A' on any downstream consumers of this value

Possibly related PRs

Suggested reviewers

  • pattonwebz

Poem

🐰 The scannable post types now shine so bright,
No more that flag leading stats astray at night,
N/A waits patiently when conditions aren't right,
Percentages calculated with logic so tight,
Quality checks now properly aligned! ✨

Pre-merge checks and finishing touches

✅ 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 summarizes the main changes: updating passed test percentage logic to include scannable post types and handle cases with no posts scanned.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch steve/no-issue/passed-test-percentage-logic

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 correctly updates the scan statistics logic to only consider scannable post types when calculating failed rules and the passed tests percentage. The logic now correctly handles cases where no posts are scanned or no post types are scannable, preventing misleading statistics. My review includes a suggestion to improve performance by reducing redundant function calls within the summary method.

$rule_query = new Issues_Query(
[
'rule_slugs' => [ $rule_slug ],
'post_types' => Settings::get_scannable_post_types(),

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

The function Settings::get_scannable_post_types() is called multiple times within the summary method (here inside a loop, and on lines 199, 206, 216, 227, 240, and 251). This can be inefficient as the function may perform database queries. To improve performance, consider calling it once at the start of the summary method, storing the result in a variable, and reusing that variable throughout the method.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a nice change here but it's somewhat out of scope of the actual thing being fixed here.

The method does make a query to get an option and then processes it but the option is autoloaded so only retrieved once from database then from memory on subsequent calls.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
admin/class-scans-stats.php (1)

198-200: passed_percentage gating avoids misleading values and divide-by-zero

Initializing passed_percentage to 'N/A' and only computing it when there are scannable post types, at least one scanned post, and tests_count > 0 cleanly prevents showing 100% when nothing has actually been scanned and also guards against division by zero when there are no tests. This aligns with how other metrics fall back to 'N/A'.

As a minor optimization, if you find yourself calling Settings::get_scannable_post_types() frequently in summary(), consider caching it in a local variable once per call, but this is optional.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 33e3c13 and c81cb15.

📒 Files selected for processing (1)
  • admin/class-scans-stats.php (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.php: Follow WordPress Coding Standards (WPCS) in all PHP files
Class names use CamelCase (ClassNameConvention) for new classes
Use edac_ prefix for all custom action/filter hook names
Ensure PHP 7.4+ compatibility
Use type hints where appropriate (parameters, return types, properties)
Sanitize inputs, validate data, and escape outputs following WordPress security best practices; use nonces for forms/AJAX
Use the WordPress database API ($wpdb) for all database operations
Prefix functions and classes in the global namespace with edac_
Use WordPress transients for caching temporary data where appropriate
All user-facing text in PHP must be translatable using the accessibility-checker text domain
Use PHPDoc for all public classes, methods, and properties
Document all custom hooks (actions/filters) with docblocks including parameters and types

Files:

  • admin/class-scans-stats.php
admin/**/*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Place admin classes and admin-only PHP code in the /admin directory

Files:

  • admin/class-scans-stats.php
**/class-*.php

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/class-*.php: Legacy PHP class files must use WordPress style naming class-class-name.php
Legacy class names use WordPress underscore style (Class_Name_Convention)

Files:

  • admin/class-scans-stats.php
🧬 Code graph analysis (1)
admin/class-scans-stats.php (1)
admin/class-settings.php (2)
  • Settings (13-98)
  • get_scannable_post_types (42-71)
🔇 Additional comments (1)
admin/class-scans-stats.php (1)

183-190: Per-rule Issues_Query restricted to scannable post types looks correct

Confining the per-rule Issues_Query to Settings::get_scannable_post_types() ensures rules_failed only reflects issues on scannable content, which matches how the rest of the stats already scope queries. Using a limit of 1 is appropriate here since you only care about existence (count() > 0), and should reduce unnecessary query work.

@pattonwebz

Copy link
Copy Markdown
Member

I updated this branch with the test changes from after 6.9 release. Test now pass again.

I also tested the code here and confirmed that the change does show N/A when there is no issues. I tested it by toggling off all my post types to get the issues cleared out.

Screenshot from 2025-12-16 13-34-49

@SteveJonesDev
SteveJonesDev merged commit 91d01bb into develop Dec 16, 2025
18 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request May 15, 2026
2 tasks
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.

2 participants