Skip to content

docs: explain the design in one page and slim AGENTS.md - #17

Merged
kasperg merged 9 commits into
mainfrom
docs/design
Oct 14, 2026
Merged

kasperg merged 9 commits into
mainfrom
docs/design

Conversation

@kasperg

@kasperg kasperg commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

The reasons for how the package is built were spread over AGENTS.md, docblocks and commit messages, and some were recorded nowhere current. AGENTS.md, which every agent session loads, carried the architecture, the conventions and the cross-cutting rationale.

This adds docs/design.md for contributors: the principles, the code structure (readers and decisions, thin providers, the directories), a table of how each part is checked and tested with the reason for each check, and the steps for adding a provider. AGENTS.md shrinks to the documentation pointers and the commands.

The first three commits:

  • Reasons beside what they explain. Docblocks and a neon comment now hold the reasons tied to one class: why OriginFiles exists, why ServiceDefinitions and DrupalFiles do not build on phpstan-drupal's maps, why the result cache hashes paths within the analysed tree, why rule tests share a container, and why Twig's keep their own.
  • Readers are autowired. autowired: false on the readers and OriginFiles had no recorded reason, and nothing depends on it. None of the PHPStan extensions this package builds on turns autowiring off, and PHPStan itself does so only to tell apart several services of one class. Readers can now be autowired into a site's own providers, as dead-code-detector's own helpers are.
  • The design page. The README links to it from Documentation, Contributing and the static-reading limitation. docs/extending.md links to the provider steps in their new place.

Six smaller commits then fix what a review of the README found: the requirements now come before the install steps, the opening sentence has a subject, list items start with a capital, the Callbacks bullet on string callbacks is split, the result-cache command runs through vendor/bin/phpstan, and the Releases paragraph is a list.

The page states reasons without saying where they came from, and gives a tool's rules only by pointing at its configuration. Whether to build on phpstan-drupal's maps is left for a separate discussion; the current reasons sit in the two readers' docblocks.

Verified locally: make checks and make lint-commits pass. Removing autowired: false was also checked on its own: analysis and all 390 tests pass. make test-mutation was not run, as no code changed.

Some reasons for how the package and its tests are built were recorded
only in AGENTS.md or in commit messages: why usages carry their files
outside dead-code-detector's origins, why the readers do not build on
phpstan-drupal's maps, why the result cache hashes paths within the
analysed tree, and why rule tests share a container while Twig's keep
their own.

State each in the docblock or config comment of what it explains:

- OriginFiles: dead-code-detector's public origins cannot name a YAML
  file, and the constructor that could is internal.
- ServiceDefinitions and DrupalFiles: what phpstan-drupal's ServiceMap
  and ExtensionMap lack, and that both are static state.
- DrupalFilesResultCacheMetaExtension: the tests excluder judges usages
  by a wiring file's place in the tree, and relative paths survive the
  checkout moving.
- DeadCodeRuleTestCase: separate containers took more code than the
  tests, and running one file analyses only its own fixtures.
- The Twig tests' neon: bare-name matching would let a template keep
  another mechanism's fixture alive in the shared analysis.

Assisted-by: Claude <noreply@anthropic.com>
The readers and OriginFiles were registered with autowired: false, with
no recorded reason. Nothing here depends on it: analysis and tests pass
without it. None of the PHPStan extensions this package builds on turns
autowiring off, and PHPStan does so only to tell apart several services
of one class, which the readers are not.

Drop the setting and the step that asked for it. The providers still
receive their readers by name.

Readers can now be autowired into a site's own providers, as
dead-code-detector's own helpers are.

Assisted-by: Claude <noreply@anthropic.com>
@kasperg
kasperg force-pushed the docs/design branch 7 times, most recently from 1d9bad4 to f40a4f3 Compare October 14, 2026 07:31
The reasons for how the package is built were spread over AGENTS.md,
docblocks and commit messages. AGENTS.md, which every agent session
loads, carried the architecture, the conventions and the cross-cutting
rationale, while some reasons were recorded nowhere current: why the
analysis is strict, why tests run in random order, and why logic moves
out of providers.

Add docs/design.md for contributors:

- Principles: reuse before building, read the site's files and never a
  running site, when unsure code is used, and the toolchain decides
  versions.
- Code structure: readers and decisions, thin providers, and the
  directories.
- How each part is checked and tested, as a table with the reason for
  each check.
- The steps for adding a provider, moved from AGENTS.md.

Slim AGENTS.md to the documentation pointers and the commands. Reasons
tied to one class are in its docblock since the previous commit. The
README links to the design page, and docs/extending.md to the provider
steps in their new place.

Assisted-by: Claude <noreply@anthropic.com>
The README opened with "[shipmonk/dead-code-detector] extension that
teaches it…", with no article, so "it" pointed back at a package name
inside a link.

Open with "A dead-code-detector extension".

Assisted-by: Claude <noreply@anthropic.com>
The supported Drupal and PHP versions, and that Drupal 10 is not
supported, came after composer require and the neon includes. A Drupal
10 site learned it was unsupported only after trying to install.

List the requirements first, under "Requires:".

Assisted-by: Claude <noreply@anthropic.com>
The lists under "Supported Drupal mechanisms" began their items in
either case, sometimes within one list.

Start every item with a capital, as most already did.

Assisted-by: Claude <noreply@anthropic.com>
The last Callbacks bullet read "They count from where they appear…;
array callables are dead-code-detector's own", leaving unclear what
"they" were and what array callables mean for the reader.

Split it in two: a callback counts from where its string appears, and
array callables such as [$this, 'method'] are dead-code-detector's to
handle.

Assisted-by: Claude <noreply@anthropic.com>
The README and docs/extending.md told readers to run
`phpstan clear-result-cache`, while the README runs PHPStan as
vendor/bin/phpstan everywhere else. Without a global PHPStan the
command fails.

Run it as vendor/bin/phpstan in both.

Assisted-by: Claude <noreply@anthropic.com>
The Releases paragraph mixed which commits make which release, what a
release produces, and the maintainer's token setup, which only a
maintainer needs and which came last.

Give each its own bullet.

Assisted-by: Claude <noreply@anthropic.com>
@kasperg
kasperg merged commit 348638c into main Oct 14, 2026
15 checks passed
@kasperg
kasperg deleted the docs/design branch October 28, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant