Skip to content

Fix 3204#143

Merged
sorinmarta merged 4 commits into
masterfrom
fix-3204
Jul 20, 2026
Merged

Fix 3204#143
sorinmarta merged 4 commits into
masterfrom
fix-3204

Conversation

@sorinmarta

@sorinmarta sorinmarta commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@sorinmarta sorinmarta added run analysis Run the phpcs run tests Run the unit tests labels Jul 20, 2026
Payment transaction constructor calls WordPress maybe_unserialize; Brain Monkey suite needs that stub or create_transaction fatals.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
includes/regions-api.php (1)

131-145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prevent fatal errors on invalid input and optimize loop execution.

Guarding the iteration with an is_array() check prevents a TypeError (especially in PHP 8) if the consumer happens to pass null or a non-array payload. Additionally, breaking out of the loop early once the maximum region count is reached avoids needlessly preparing and filtering excess items.

♻️ Proposed refactor
+        if ( ! is_array( $regions ) ) {
+            return;
+        }
+
         $count = 0;
 
         foreach ( $regions as $region ) {
+            if ( $count >= $max_regions ) {
+                break;
+            }
+
             $data = $this->prepare_submitted_region( $region );
 
             if ( empty( implode( $data ) ) ) {
                 continue;
             }
 
-            if ( $count < $max_regions ) {
-                $this->save( array_merge( $data, array( 'ad_id' => $ad->ID ) ) );
-            }
+            $this->save( array_merge( $data, array( 'ad_id' => $ad->ID ) ) );
 
             ++$count;
         }
🤖 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/regions-api.php` around lines 131 - 145, Update the
region-processing loop around prepare_submitted_region to iterate only when
$regions is an array, preventing invalid null or non-array input from causing a
TypeError. Stop iteration once the maximum region count is reached, while
preserving the existing empty-data filtering and save behavior for eligible
regions.
🤖 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.

Nitpick comments:
In `@includes/regions-api.php`:
- Around line 131-145: Update the region-processing loop around
prepare_submitted_region to iterate only when $regions is an array, preventing
invalid null or non-array input from causing a TypeError. Stop iteration once
the maximum region count is reached, while preserving the existing empty-data
filtering and save behavior for eligible regions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85d76d54-2fad-4861-98d5-19f676620d99

📥 Commits

Reviewing files that changed from the base of the PR and between 0975ac9 and d91257f.

📒 Files selected for processing (1)
  • includes/regions-api.php

set_status walks the full verification chain, so tests need get_awpcp_option, awpcp_payments_api, and a money item before asserting payment-status gates.
@Strategy11 Strategy11 deleted a comment from coderabbitai Bot Jul 20, 2026
@sorinmarta
sorinmarta merged commit 42a0e01 into master Jul 20, 2026
5 checks passed
@sorinmarta
sorinmarta deleted the fix-3204 branch July 20, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run analysis Run the phpcs run tests Run the unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant