Skip to content

v2.1.8 — Phase 9.12 shortcode + campaign redirect extraction

Choose a tag to compare

@mexiter mexiter released this 25 Apr 14:29
· 66 commits to epic/refactor-april since this release

Phase 9.12 — shortcode + campaign redirect extraction

The two remaining public entry points leave the god-class for dedicated single-responsibility classes under src/Frontend/Shortcode/ and src/Frontend/Redirect/.

Three new classes

  • ToplistShortcode — validates attrs, looks up toplist via ToplistsRepository (slug-or-id), runs the H7 BrandMetaPrefetcher once before iterating items, dispatches each item to CardRenderer::render(CasinoCardVM) or to TableRenderer::render(ToplistTableVM).
  • ShortcodeRegistrar — owns the add_shortcode('dataflair_toplist', …) registration. Wired through a generic callable so heavy-weight orchestrator construction is deferred to first invocation — every other plugin has had a chance to register its dataflair_card_renderer / dataflair_table_renderer filters before the renderer resolves through the lazy Container.
  • CampaignRedirectHandler — owns template_redirect, validates the campaign param, increments the per-campaign hit-counter transient, calls wp_safe_redirect() to the brand affiliate URL.

Main file trim

dataflair-toplists.php drops by ~177 LOC. Two god-class methods become one-line delegators wired through lazy Container getters. add_shortcode + add_action('template_redirect', …) registrations move to Plugin::registerHooks().

Invariants preserved

  • Render-time read-only: ToplistShortcode::render() still passes the H7 prefetched brand-meta map into every CasinoCardVM. RenderIsReadOnlyTest + RenderBatchQueryCountTest continue to enforce this — both H* invariants now point to the new class file at the source-scan layer.
  • Public contract: shortcode HTML is byte-identical, campaign redirect URL pattern (/go/?campaign=…) and per-campaign hit-counter transient unchanged. AJAX endpoints, REST endpoints, sync semantics, telemetry hooks: identical.

Tests

21 new unit tests pin attribute validation, repository lookup, prefetch ordering, dispatch into table vs cards, the registrar's function_exists guard, the campaign happy path, the invalid-campaign 404, the already-redirected guard, and the per-campaign hit-counter transient. Full suite: 574 tests, 1,270 assertions, all green.

Strangler-fig

The two extracted god-class methods remain as one-line delegators through v2.1.x. They are deleted in v3.0.0 (Phase 9.13 — god-class symbol removal).