Skip to content

fix(controller): remove unreachable || true / && false guards - #148

Open
faisalahammad wants to merge 1 commit into
wpexpertsio:old/devfrom
faisalahammad:fix/111-remove-unreachable-code
Open

fix(controller): remove unreachable || true / && false guards#148
faisalahammad wants to merge 1 commit into
wpexpertsio:old/devfrom
faisalahammad:fix/111-remove-unreachable-code

Conversation

@faisalahammad

Copy link
Copy Markdown

Summary

Two debug-disable hacks in Postman/Postman-Controller/PostmanAdminPointer.php made the constructor's hook registrations and the pointer array build unreachable. Both are now removed. The WP version compare is also upgraded from a lexicographic string < to version_compare() so the guard stays correct on future WP releases.

Behaviour is unchanged at runtime because the class is loaded but never instantiated elsewhere.

Fixes #111

Changes

Postman/Postman-Controller/PostmanAdminPointer.php

Constructor guard — Before:

// Don't run on WP < 3.3
if (get_bloginfo ( 'version' ) < '3.3' || true)
    return;

Constructor guard — After:

// Don't run on WP < 3.3
if (version_compare ( get_bloginfo ( 'version' ), '3.3', '<' ))
    return;

Why: || true forced an early return regardless of WP version, making the add_action and add_filter calls immediately below it unreachable. The lexicographic string compare was also broken: with '10.x' the expression '10.0' < '3.3' becomes true and the guard would fire on newer WP. version_compare() fixes both.

Pointer registration guard — Before:

// only do this for administrators
if (PostmanUtils::isAdmin () && false) {
    $p ['postman16_log'] = array (
            'target' => '.configure_manually',
            ...
    );
    return $p;
}

Pointer registration guard — After:

// only do this for administrators
if (PostmanUtils::isAdmin ()) {
    $p ['postman16_log'] = array (
            'target' => '.configure_manually',
            ...
    );
    return $p;
}

Why: && false short-circuited the role check and skipped the pointer registration. PostmanUtils::isAdmin() is the actual intent.

Testing

Test 1: Syntax lint

  1. From a local clone: php -l Postman/Postman-Controller/PostmanAdminPointer.php
  2. Result: reports No syntax errors detected. Confirmed in the fix branch.

Test 2: Runtime smoke on a WP 5.6+ site

  1. Install and activate the plugin from the branch.
  2. Load each admin page that Post SMTP owns: Post SMTP dashboard widget, Postman → Configuration, Email Log, Send Test Email, Connectivity Test.
  3. Result: no PHP fatals, no notices, no warnings. Behaviour identical to old/dev because the class is still loaded but not instantiated.

Test 3: Inline diff review

  1. Open Postman/Postman-Controller/PostmanAdminPointer.php.
  2. Confirm L27 is now an honest version guard and L101 is now an honest role check.

Notes

Two adjacent issues were observed during investigation and are intentionally not addressed in this PR so the diff stays surgical:

  • Postman/Postman-Email-Log/PostmanEmailLogService.php:285 has the same || true debug-disable flavor. Worth a separate cleanup.
  • The pointer JS asset script/postman-admin-pointer.js referenced at PostmanAdminPointer.php:89 does not exist in the repo and the matching wp_enqueue_script block is commented out. So even if the class is later instantiated, the pointer will not render until the JS is added.

Happy to follow up on either in a separate issue if useful.

Two debug-disable hacks in PostmanAdminPointer made the constructor
and the pointer registration block unreachable:

- constructor's WP < 3.3 guard used '|| true' to force an early
  return regardless of WP version
- wptuts_register_pointer_testing() admin guard used '&& false'
  to skip the pointer array build

Dropped both hacks and replaced the lexicographic string version
compare with version_compare() so the guard stays correct on future
WP releases (e.g. '10.x' < '3.3' would silently flip the earlier
check).

The class is still loaded but not instantiated elsewhere, so runtime
behaviour is unchanged.

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

Unreachable code

1 participant