Simplify slice 1l: PatternContext takes StyleResolver instead of three forwarding closures

Open Beginner friendly
#4,874 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Read Patterns/PatternContext.php and HtmlCompilation.php around the two construction sites. Replace the three forwarding closures with the StyleResolver dependency and update both calls, preserving the existing null defaults. Check the listed test construction sites for positional arguments, then run the php-transformer gates; done means byte-identical output and fewer net lines.

Written by the indexing model from the issue text.

Description

Part of #4368. A follow-up to #4723 (PatternContext takes DisclosureControlPresentation).

Problem

Patterns/PatternContext still takes three optional closures that only forward to StyleResolver. HtmlCompilation builds each of them twice, which makes 6 closures:

PatternContext param Forwards to createPatternContext() (positional, about lines 3978 to 3987) createProbePatternContext() (named, about lines 4074 to 4077)
authoredIconColor authoredInheritedPropertyWinner($el, 'color') yes yes
sourceElementVisuallyClipped isVisuallyClippedBox($el) yes yes
socialPresentationDeclarations resolvedPresentationDeclarations($el) yes yes

Change

  1. PatternContext replaces those three ?Closure params with one ?StyleResolver $styles = null (Style/StyleResolver), placed where authoredIconColor is now.
    • authoredIconColor(), sourceElementVisuallyClipped() and socialPresentationDeclarations() delegate to $this->styles, keeping today's null defaults: '', false and [].
    • Delete the three fields and their @param lines.
  2. Update both construction sites in HtmlCompilation. The first one is positional, so pass $this->styleResolver in the old authoredIconColor slot and drop the other two closure arguments, keeping every remaining argument in order. Alternatively, switch that call to named arguments.
  3. Test construction sites: tests/unit/pattern-recognizer-registry.php, pattern-registry-staged-dispatch.php, button-link-dispatcher.php, flow-container-element-converter.php and tests/contract/run.php. Check them all: none passes these three params today, so they should need no changes. If any passes positional arguments past authoredIconColor, update it.

Read only HtmlCompilation.php (lines 3920 to 4080), Patterns/PatternContext.php and the test files listed above.

Acceptance

  • Byte-identical output; the php-transformer gates pass.
  • Net lines go down.
  • The PR body reports closures removed (6) and net lines.

AI assistance: scoped by Claude Opus (Anthropic) via Pi/Roadie.

Dominant language
PHP
Stars
25
Forks
3
Avg merge
2h 29m
Merged PRs (30d)
931

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Automattic/blocks-engine

All issues in Automattic/blocks-engine

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.