Skip to content

Guard EDAC_KEY_VALID usage in options page#1402

Open
SteveJonesDev wants to merge 1 commit intodevelopfrom
codex/fix-edac-key-valid-guard
Open

Guard EDAC_KEY_VALID usage in options page#1402
SteveJonesDev wants to merge 1 commit intodevelopfrom
codex/fix-edac-key-valid-guard

Conversation

@SteveJonesDev
Copy link
Copy Markdown
Member

@SteveJonesDev SteveJonesDev commented Feb 14, 2026

Summary

  • guard the EDAC_KEY_VALID check in edac_post_types_cb() with defined() to avoid undefined-constant errors when the file is loaded outside normal bootstrap
  • add OptionsPageSourceTest to lock in the constant guard at source level

Testing

  • php -l includes/options-page.php
  • php -l tests/phpunit/includes/OptionsPageSourceTest.php
  • npm run test:php (fails in this environment: Docker socket permission denied at /Users/stevejones/.docker/run/docker.sock)

Risk

  • Low. Change is a single conditional guard in settings rendering path; behavior is unchanged when EDAC_KEY_VALID is defined.

Summary by CodeRabbit

  • Bug Fixes

    • Resolved a potential PHP notice error that could occur when a specific configuration constant was not defined. The application now properly checks whether the constant exists before attempting to use it, improving stability.
  • Tests

    • Added test coverage to verify the application properly guards against undefined constants.

@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 enhances the robustness of the options page by preventing potential PHP errors related to an undefined constant. It ensures that the EDAC_KEY_VALID constant is only evaluated if it has been defined, thereby improving stability, especially in non-standard loading scenarios. A new test has been introduced to safeguard this critical check.

Highlights

  • Error Prevention: Implemented a defined() check for EDAC_KEY_VALID in edac_post_types_cb() to prevent undefined-constant errors when the file is loaded outside the normal bootstrap process.
  • Test Coverage: Added a new PHPUnit test, OptionsPageSourceTest, to specifically verify that the EDAC_KEY_VALID constant is always checked with defined() before usage.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • includes/options-page.php
    • Modified the conditional check for EDAC_KEY_VALID to include a defined() check, preventing potential undefined constant errors.
  • tests/phpunit/includes/OptionsPageSourceTest.php
    • Added a new test file to verify that the EDAC_KEY_VALID constant is properly guarded with defined() before usage in includes/options-page.php.
Activity
  • The author performed local testing using php -l for syntax checks on both the modified options page file and the new test file.
  • The author attempted to run npm run test:php but encountered a 'Docker socket permission denied' error, indicating a local environment issue rather than a code problem.
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
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 14, 2026

Walkthrough

A PHP notice prevention was implemented by guarding the EDAC_KEY_VALID constant check with a defined() condition, and a corresponding test was added to verify the guard is in place within the source code.

Changes

Cohort / File(s) Summary
Defensive Programming
includes/options-page.php
Added guard clause using defined() to check EDAC_KEY_VALID existence before use, preventing potential PHP notices if the constant is undefined.
Test Coverage
tests/phpunit/includes/OptionsPageSourceTest.php
New test file added to verify that the options-page.php source contains the guarded EDAC_KEY_VALID constant check.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

codex

Suggested reviewers

  • pattonwebz

Poem

🐰 A careful rabbit guards each leap,
Before constants wake from sleep,
With defined() checks held tight,
No PHP notices blight the night! ✨

🚥 Pre-merge checks | ✅ 4
✅ 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 directly and accurately summarizes the main change: adding a defined() guard around EDAC_KEY_VALID usage in the options page to prevent PHP notices.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into develop

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

✨ 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 codex/fix-edac-key-valid-guard

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 guards the usage of the EDAC_KEY_VALID constant with a defined() check to prevent errors when the file is loaded in different contexts. It also introduces a new test to ensure this guard remains in place. The changes are logical and improve the robustness of the code. I've added one suggestion to improve the new test by making it less brittle to future formatting changes.

Comment on lines +22 to +25
$this->assertStringContainsString(
"defined( 'EDAC_KEY_VALID' ) && false === EDAC_KEY_VALID",
$source
);
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

While assertStringContainsString works, it makes this test brittle. Any minor formatting change to the condition in the source code (like adding or removing whitespace) will cause this test to fail. Using assertMatchesRegularExpression with a regular expression that allows for whitespace variations will make the test more robust and less likely to fail on trivial formatting changes. You can replace the multi-line assertion with a single line for conciseness.

		$this->assertMatchesRegularExpression("~defined\\(\\s*'EDAC_KEY_VALID'\\s*\\)\\s*&&\\s*false\\s*===\\s*EDAC_KEY_VALID~", $source);

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

🤖 Fix all issues with AI agents
In `@tests/phpunit/includes/OptionsPageSourceTest.php`:
- Around line 1-12: The test class OptionsPageSourceTest is in the global
namespace and lacks the required edac_ prefix and
EqualizeDigital\AccessibilityChecker namespace; move the class into the
EqualizeDigital\AccessibilityChecker namespace and either import WP_UnitTestCase
with a use statement or fully qualify it, and rename the class to include the
edac_ prefix (e.g., edac_OptionsPageSourceTest) so it follows the
PSR-4/autoloading and global-prefix rules while keeping references to
WP_UnitTestCase intact.

Comment on lines +1 to +12
<?php
/**
* Tests for options-page source safety checks.
*
* @package Accessibility_Checker
*/

/**
* Verify options page source keeps EDAC_KEY_VALID usage guarded.
*/
class OptionsPageSourceTest extends WP_UnitTestCase {

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

Align the new test class with namespace/prefix guidelines.

This class is in the global namespace without the required edac_ prefix and doesn’t use the required EqualizeDigital\AccessibilityChecker namespace for new classes. Consider namespacing it (and importing WP_UnitTestCase) to satisfy both rules.

🔧 Suggested update
 <?php
+namespace EqualizeDigital\AccessibilityChecker\Tests\PHPUnit\Includes;
+
+use WP_UnitTestCase;
 /**
  * Tests for options-page source safety checks.
  *
  * `@package` Accessibility_Checker
  */
@@
-class OptionsPageSourceTest extends WP_UnitTestCase {
+class OptionsPageSourceTest extends WP_UnitTestCase {

As per coding guidelines, "Use PSR-4 autoloading with EqualizeDigital\AccessibilityChecker namespace for new classes" and "Prefix all functions and classes in global namespace with 'edac_'".

🤖 Prompt for AI Agents
In `@tests/phpunit/includes/OptionsPageSourceTest.php` around lines 1 - 12, The
test class OptionsPageSourceTest is in the global namespace and lacks the
required edac_ prefix and EqualizeDigital\AccessibilityChecker namespace; move
the class into the EqualizeDigital\AccessibilityChecker namespace and either
import WP_UnitTestCase with a use statement or fully qualify it, and rename the
class to include the edac_ prefix (e.g., edac_OptionsPageSourceTest) so it
follows the PSR-4/autoloading and global-prefix rules while keeping references
to WP_UnitTestCase intact.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant