Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

generate-fixtures output is unreadable as a maintained fixture

已关闭
#452 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #453 来自 @silverbackdan —— 已合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
活跃
技术栈
php
领域
tooling

调研方向

Start in GenerateFixturesCommand, reading emitComponent(), emitGroup(), exportValue(), build() and the $deferredReferences / afterRoutes() handling. Generate a fixture from a small site and compare it with the output. Done when the generated class has readable variable names, inline references, nowdoc HTML, opt-in timestamps and per-page methods, and still reloads to the same rows.

由索引模型根据 Issue 内容生成。

描述

enhancement

silverback:api-components:generate-fixtures (2.0.0-alpha.18) reproduces a site faithfully. A snapshot of a production site with 18 pages, 66 groups, 119 components and 13 images reloads with every content row matching. But the class it writes can't be maintained as a fixture: a developer opening it found it unreadable. The causes are all in GenerateFixturesCommand:

  1. Positional variables. Every component is $c[n] and every group $g[n], numbered in walk order (emitComponent(), emitGroup()). $c[35]->html = ... says nothing about what it is.
  2. References are written far from their component. Every non-component association (e.g. a navigation link's route) is deferred to an afterRoutes() block at the end of the file ($deferredReferences). A link is created on line 35 and given its route 600 lines later as $c[3]->route = $cwa->getRoute('/about/team').
  3. HTML on one line. exportValue() uses var_export(), so rich HTML becomes a single quoted string. The longest line in the snapshot is 12,963 characters.
  4. Timestamps on everything. Every publishable component gets setPublishedAt(new \DateTime('2026-10-02T14:48:09.000000+00:00')): 81 of them in a 649-line file.
  5. No structure. build() is a single flat method, with no marker where each page starts, and the layout's groups are written before any page.
  6. Lists written with index keys. uiClassNames and other plain lists come out as [0 => '...'].
Requested
  1. Readable variable names. Derive them from the short class name plus an identifying value (label, title, reference or the owning page's reference), e.g. $aboutTeamLink or $homeHeroGroup, with a numeric suffix only to resolve clashes. Don't create a variable at all for components nothing refers to later.
  2. Set references inline. afterRoutes() exists only because the target route isn't built yet. A lazy builder reference resolved on flush (e.g. $cwa->routeRef('about-team')) would let the generator write $link->route = $cwa->routeRef('about-team') next to the link. Keep afterRoutes() for draft components only.
  3. Readable HTML. Emit long HTML as a nowdoc with a line break after each block-level closing tag. Alternatively, add an option to write each one to assets/html/<name>.html and load it with file_get_contents(__DIR__ . '/assets/html/<name>.html').
  4. Timestamps opt-in. By default, emit a single "published" call per component (e.g. $cwa->publish($x), published at load time) instead of the exact publishedAt. Add --keep-timestamps for exact copies.
  5. Structure. At minimum, write a comment header for each layout and page, e.g. // Page: About - Team (/about/team). Better: one private method per layout and top-level page, called from build(), keeping nested children inside their parent's method.
  6. Plain lists. Use array_is_list() in exportValue() so lists are written as ['a', 'b'].

The expected result: running generate-fixtures against a live site gives a class a developer can read, edit and review in a diff as easily as a hand-written AbstractCwaScaffold, while still reloading to the same rows.

主要语言
PHP
星标
32
派生
8
平均合并
1 小时
30 天内合并 PR
186

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

components-web-app/api-components-bundle 的其他 Issue

查看 components-web-app/api-components-bundle 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。