Skip to content

fix(email-log): correct default values for get_all_logs and save methods - #145

Open
faisalahammad wants to merge 1 commit into
wpexpertsio:old/devfrom
faisalahammad:fix/102-parameter-defaults
Open

fix(email-log): correct default values for get_all_logs and save methods#145
faisalahammad wants to merge 1 commit into
wpexpertsio:old/devfrom
faisalahammad:fix/102-parameter-defaults

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Fixed two incorrect default parameter values caught by PHPStan. Both are small type-safe adjustments that prevent potential SQL issues and type mismatches.

Fixes #102

Changes

PostmanEmailQueryLog::get_all_logs()

Before:

public function get_all_logs( $ids = array() ) {

After:

public function get_all_logs( $ids = array(-1) ) {

Why: Empty array default produced `` after implode, so the $ids == -1 guard never matched. SQL query would generate invalid `WHERE id IN ()` when no logs selected for export.

PostmanEmailLogs::save()

Before:

public function save( $data, $id = '' ) {

After:

public function save( $data, $id = 0 ) {

Why: $id default was a string but update() expects an integer. The !empty() check works with both, but the type should match.

Testing

Test 1: Export CSV with no log items selected

  1. Go to Post SMTP > Email Log
  2. Click Export without selecting any rows
  3. Result: All logs are exported instead of invalid SQL error

Test 2: Save log entry (new)

  1. Send a test email through Post SMTP
  2. Check the Email Log
  3. Result: Log entry saved successfully

Test 3: Save log entry (update)

  1. Send an email (creates log entry)
  2. Trigger an update to that log entry
  3. Result: Log entry updated successfully

- PostmanEmailQueryLog::get_all_logs: default $ids as array(-1) instead
  of empty array. Empty array collapsed to '' after implode, so the
   == -1'' guard never matched and the query produced invalid
  WHERE id IN ()''.
- PostmanEmailLogs::save: default $id as 0 instead of '' so the
  parameter type matches update(), which expects an int.

Fixes wpexpertsio#102
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.

Parameter default values

1 participant