Simplify slice 1g: move the 10 most-wired leaf methods out of HtmlCompilation and delete their 33 closures

Open
#4,637 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
backend

Research direction

Read HtmlCompilation.php, the listed methods, and the consumers that receive them through constructor closures; inspect SourceBlockCreator and the existing style or presentation services to identify suitable owners. Trace the constructor wiring and internal call sites before moving the methods and removing closure parameters, fields, and forwarders. Run the php-transformer gates and compare output byte for byte; report closures removed, the HtmlCompilation.php line change, and net lines.

Written by the indexing model from the issue text.

Description

Part of #4368. Measured at trunk after #4634.

Problem

43 closure-wired methods in HtmlCompilation, behind 66 constructor closures, call no other HtmlCompilation method except createBlock and attr. They only use services, the session or static helpers, so they don't need to live in HtmlCompilation, and the closures exist only to reach them.

Scope: the 10 most-wired, 33 closures

Method Closures Lines Notes
htmlPreservationBlock 8 5 createBlock('core/html', safeFallbackHtml(..., tagMarkers))
disclosureControlPresentation 6 10
codePresentationAttributes 3 15
recognizePatterns 3 14
requiredScriptsForElement 3 11
runtimeAuthoredButton 2 32 uses createBlock
socialAnchorColors 2 14
rememberAccordionDisclosureRoot 2 9
imageDimensions 2 8
parsedCssSelector 2 5

Change

  1. Move each method to its natural owner:
    • htmlPreservationBlock goes onto SourceBlockCreator, or a small service next to it. Converters already receive SourceBlockCreator.
    • Presentation and attribute helpers go to the existing style or presentation service they read from.
    • Use a new small service only when no existing owner fits.
    • If a method has one consumer, move it into that consumer.
  2. Every consumer that received one of these methods as a closure gets the owning service instead. Delete those closure parameters, fields and forwarders, plus the constructor wiring.
  3. HtmlCompilation's own internal call sites call the new owner directly. Delete the methods from HtmlCompilation.
  4. Keep the change mechanical. The other 33 leaf methods are follow-up work.

Acceptance

  • Byte-identical output across all php-transformer gates.
  • The PR body reports closures removed (target 33), the HtmlCompilation.php line change, and net lines (which must go down).
  • No new tests.

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

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

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.