Skip to content

fix: guard the Black Friday callback against a missing default config - #4717

Open
vytisbulkevicius wants to merge 1 commit into
developmentfrom
fix/blackfriday-default-warning
Open

vytisbulkevicius wants to merge 1 commit into
developmentfrom
fix/blackfriday-default-warning

Conversation

@vytisbulkevicius

Copy link
Copy Markdown
Contributor

Reading $configs['default'] in the themeisle_sdk_blackfriday_data callback emitted an Undefined array key "default" warning when an earlier filter had dropped that entry. Guard it, matching the otter-blocks fix (#3198).

What changed

  • inc/admin/dashboard/main.php — add_black_friday_data() returns $configs unchanged when default is absent/empty, before reading it. Typed the array param and return.
  • phpstan-baseline.neon — dropped the two now-redundant missingType.iterableValue entries the typed docblock resolves.

QA

  1. Add a filter that empties the SDK config: add_filter( 'themeisle_sdk_blackfriday_data', '__return_empty_array', 999 );.

  2. Load any admin screen with WP_DEBUG on.

    Expect: no Undefined array key "default" warning. Without the filter, the Black Friday data still renders as before.

Refs #4716 (base is development, not the default branch master, so link via the Development sidebar)

An earlier filter on themeisle_sdk_blackfriday_data can drop the 'default' entry,
or empty the list to opt out of the sale. Reading $configs['default'] then emitted
an "Undefined array key \"default\"" warning. Return $configs early when it is
absent, matching the otter-blocks fix. Also type the callback's array param and
return, and drop the now-redundant PHPStan baseline entries.
@pirate-bot

Copy link
Copy Markdown
Collaborator

Plugin build for 60608bc is ready 🛎️!

@pirate-bot pirate-bot left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Approved

This approves the guard; the inline comment asks for a PHPUnit case that covers the new early return.

Questions for the author

  • Does the installed SDK (3.3.72, src/Modules/Announcements.php) handle a config without default or neve, including []? A source read suggests it does, but no run confirmed it.
Validation details
  • Files reviewed: 2/2 changed files.
  • SDK 3.3.72 source read: it picks default or a fallback and stops on an empty array.
  • The SDK's own producer always sends a non-empty default.
  • No other SDK filter callback reads a removable key without a guard.
  • The two removed baseline entries match the errors the new docblock types resolve.
Untested areas
  • PHPStan and PHPUnit were not run. CI owns them.
  • The admin screen with WP_DEBUG was not loaded in a site.

🤖 Automated review · run code-review-agent_6b05493291d1f7.89801139.


🤖 Review agent — review posted ✅ on 60608bc7 · approved · 1 finding · 14 min

Run code-review-agent_6b05493291d1f7.89801139 · trail

Comment on lines +1467 to +1470
// An earlier filter may drop the default entry, or empty the list to opt out of the sale.
if ( empty( $configs['default'] ) ) {
return $configs;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

tests Add a PHPUnit case for the new guard. No test exercises add_black_friday_data(), so a regression of the Undefined array key "default" warning would pass CI. Add tests/test-neve-black-friday-data.php in the style of tests/test-neve-support-hub.php. Call add_black_friday_data() on a Main instance and assert that array() and an array without default come back unchanged with no neve key. These cases fail on the base code because phpunit.xml converts warnings to exceptions. Also assert that a non-empty default still gets a neve entry.

This branch has not been deployed

No deployments
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.

2 participants