Skip to content

Udp.Code.Constants - #849

Open
alexander-b-clean wants to merge 9 commits into
devfrom
dev-constants.ag-2
Open

Udp.Code.Constants#849
alexander-b-clean wants to merge 9 commits into
devfrom
dev-constants.ag-2

Conversation

@alexander-b-clean

Copy link
Copy Markdown
Contributor

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.75000% with 98 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.65%. Comparing base (a86e723) to head (973be05).
⚠️ Report is 9 commits behind head on dev.

Files with missing lines Patch % Lines
lib/Cleantalk/ApbctWP/Constant.php 39.68% 76 Missing ⚠️
...tispam/Integrations/CleantalkPreprocessComment.php 0.00% 6 Missing ⚠️
cleantalk.php 16.66% 5 Missing ⚠️
inc/cleantalk-common.php 50.00% 2 Missing ⚠️
inc/cleantalk-public.php 50.00% 2 Missing ⚠️
inc/cleantalk-settings.php 66.66% 2 Missing ⚠️
...antalk/Antispam/IntegrationsByClass/BuddyPress.php 0.00% 1 Missing ⚠️
lib/Cleantalk/ApbctWP/Activator.php 0.00% 1 Missing ⚠️
lib/Cleantalk/ApbctWP/AdminNotices.php 0.00% 1 Missing ⚠️
lib/Cleantalk/ApbctWP/Firewall/AntiCrawler.php 50.00% 1 Missing ⚠️
... and 1 more

❌ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

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\Constant as a central static service-constant registry (with legacy aliases).
  • Removes ServiceConstants / ApbctConstant and drops $apbct->service_constants from State.
  • 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.

Comment thread lib/Cleantalk/ApbctWP/Constant.php Outdated
Comment thread inc/cleantalk-public.php
Comment on lines 44 to 48
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 {

@alexander-b-clean alexander-b-clean Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread lib/Cleantalk/Antispam/Integrations/CleantalkPreprocessComment.php Outdated
Comment thread tests/Inc/TestCleantalkCommon.php
Comment on lines +207 to +211
public static function is($constant, $expected_value = null)
{
$defined_name = self::getDefinedName($constant);

if ( $defined_name === false ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@alexander-b-clean alexander-b-clean changed the title Constants Udp.Code.Constants Aug 4, 2026
alexander-b-clean and others added 5 commits August 4, 2026 17:25
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>
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.

4 participants