Udp.Code.Constants - #849
Conversation
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (38.75%) is below the target coverage (70.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## dev #849 +/- ##
============================================
+ Coverage 27.63% 27.65% +0.01%
- Complexity 6061 6086 +25
============================================
Files 282 282
Lines 25191 25328 +137
============================================
+ Hits 6962 7004 +42
- Misses 18229 18324 +95 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR replaces the runtime $apbct->service_constants object (and its supporting classes) with a static Cleantalk\ApbctWP\Constant registry, and updates call sites/tests accordingly to use static constant resolution.
Changes:
- Introduces
Cleantalk\ApbctWP\Constantas a central static service-constant registry (with legacy aliases). - Removes
ServiceConstants/ApbctConstantand drops$apbct->service_constantsfromState. - Updates multiple modules and tests to use
Constant::is()/Constant::getValue()and adjusts localized output.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Inc/TestCleantalkCommon.php | Removes constant-injection tests; replaces with explanatory note about static constants. |
| tests/ApbctWP/TestServiceConstants.php | Removes PHPUnit coverage for the old ServiceConstants object. |
| tests/ApbctWP/Localize/TestCtPublicFunctionsLocalize.php | Updates localization expectations (adds data__bot_detector_enabled). |
| lib/Cleantalk/ApbctWP/State.php | Removes $service_constants property/initialization. |
| lib/Cleantalk/ApbctWP/ServiceConstants.php | Deletes the old service-constants container class. |
| lib/Cleantalk/ApbctWP/ApbctConstant.php | Deletes the old per-constant helper class. |
| lib/Cleantalk/ApbctWP/RemoteCalls.php | Switches debug output to Constant::getDefinitionsActive(). |
| lib/Cleantalk/ApbctWP/Localize/CtPublicFunctionsLocalize.php | Uses Constant for frontend-data-log flag and adds numeric bot-detector flag. |
| lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php | Replaces $apbct->service_constants access with Constant calls. |
| lib/Cleantalk/ApbctWP/Constant.php | Adds the new static registry and helpers (is, getValue, getNames, definitions). |
| lib/Cleantalk/ApbctWP/AdminNotices.php | Replaces direct defined(...) checks with Constant usage for access-key logic. |
| lib/Cleantalk/ApbctWP/Activator.php | Uses Constant to detect predefined/self-owned access key. |
| lib/Cleantalk/Antispam/IntegrationsByClass/BuddyPress.php | Uses Constant::getValue() for comment-count threshold. |
| lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php | Uses Constant for comment-count threshold and blocking-title behavior. |
| inc/cleantalk-settings.php | Replaces multiple direct-constant checks with Constant for settings/UI logic. |
| inc/cleantalk-public.php | Uses Constant for footer placement and blocking title behavior. |
| inc/cleantalk-pluggable.php | Uses Constant::getValue() to force AJAX route type. |
| inc/cleantalk-common.php | Uses Constant for bot-detector constants and POST-data exception behavior. |
| cleantalk.php | Adds Constant import and updates some access-key and whitelabel constant handling. |
Suppressed comments (4)
inc/cleantalk-public.php:827
- Constant::is() without an expected value returns true for any defined boolean constant (even if defined as false). If the intent is to disable the branding/title only when the constant is set to true, use Constant::is(..., true).
$message_title = __('Spam protection', 'cleantalk-spam-protect');
if ( ! Constant::is(Constant::APBCT_SERVICE__DISABLE_BLOCKING_TITLE) ) {
$message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
}
inc/cleantalk-public.php:884
- Same as ct_die(): Constant::is() without an expected value treats a defined-false constant as enabled. Use the value-aware check if the title should only be disabled when the constant is explicitly true.
$message_title = __('Spam protection', 'cleantalk-spam-protect');
if ( ! Constant::is(Constant::APBCT_SERVICE__DISABLE_BLOCKING_TITLE) ) {
$message_title = '<b style="color: #49C73B;">Clean</b><b style="color: #349ebf;">Talk.</b> ' . $message_title;
}
cleantalk.php:148
- This still checks CLEANTALK_SERVER directly, so the new canonical APBCT_SERVICE__PREDEFINED_CLEANTALK_SERVER_URL name won’t be honored. Also the TODO references the removed $apbct->service_constants. Consider resolving the server via Constant::is/getValue so both canonical and legacy names work consistently.
//todo make this as $apbct->service_constants
if ( defined('CLEANTALK_SERVER') ) {
define('APBCT_MODERATE_URL', 'https://moderate.' . CLEANTALK_SERVER);
if ( ! defined('CLEANTALK_API_URL') ) {
define('CLEANTALK_API_URL', 'https://api.' . CLEANTALK_SERVER);
inc/cleantalk-public.php:1267
- $in_footer is currently based on Constant::is() which returns true for any defined boolean constant (even if it’s defined as false). This differs from the previous behavior and can enqueue scripts in the footer unexpectedly.
$in_footer = Constant::is(Constant::APBCT_SERVICE__PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if ( ! apbct_exclusions_check__url() ) { | ||
| if (defined('CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER') && CLEANTALK_PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER) { | ||
| if (Constant::is(Constant::APBCT_SERVICE__PLACE_PUBLIC_JS_SCRIPTS_IN_FOOTER)) { | ||
| add_action('wp_footer', array(LocalizeHandler::class, 'handle'), 1); | ||
| add_action('login_footer', array(LocalizeHandler::class, 'handle'), 1); | ||
| } else { |
| public static function is($constant, $expected_value = null) | ||
| { | ||
| $defined_name = self::getDefinedName($constant); | ||
|
|
||
| if ( $defined_name === false ) { |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
https://app.doboard.com/1/task/38754