notes · · 5 min · updated 2026-10-27

Composer Under the Microscope: What 67 Remote AST Tools Found Inside the PHP Dependency Manager

Analysis of the PHP dependency manager Composer with prod-code: 139,690 lines across 634 files, a 12-node zero-edge dependency extraction, Boolean SAT resolution, 2-watched literal graphs, and 2,536 test assertion matching lines.

On this page · 5 sections
  1. Subsystem Architecture: Decoupled Package & Solver Pipelines
  2. The Boolean Satisfiability (SAT) Solver
  3. Clone Analysis and Test Repetitions
  4. Matching-Line Counts: 2,536 Assertion Lines and 620 Throw Lines
  5. Remote AST Operations on Cluster Nodes

First published on 2026-10-04. The measurements reported in this article are historical and have not been re-run for this revision.

Before Composer, PHP package management meant downloading tarballs, managing PEAR channels, or checking vendor code directly into version control. Created by Jordi Boggiano and Nils Adermann in 2011, Composer revolutionized PHP by introducing standard declarative composer.json dependency declarations, universal PSR-4 autoloading, and an industrial-grade Boolean Satisfiability (SAT) constraint solver.

Today, Composer orchestrates package installations for millions of PHP developers and servers worldwide. Resolving transitive version requirements across complex ecosystems is inherently NP-complete, requiring sophisticated graph algorithms and Conflict-Driven Clause Learning (CDCL).

To examine how Composer structures its package repositories, SAT resolution engine, and autoloader generators, we deployed operations from prod-code’s 67-tool suite against a checkout on a remote 32-core cluster node (node-b:9400). The original checkout SHA was not preserved; measurements and source line references are historical and cannot be independently reproduced against a pinned revision.

$ git ls-files '*.php' | wc -l
634
$ git ls-files -z '*.php' | xargs -0 wc -l | tail -n 1
139690 total
$ git ls-files | awk -F. '{if (NF>1) print $NF}' | sort | uniq -c | sort -nr | head -n 6
 634 php
 265 test
 111 json
  46 md
  18 zip
  11 yml

The captured inventory shows 139,690 lines of PHP across 634 source files:

  • Core Library & Subsystems (src/Composer/): 77,174 lines across 314 files.
  • Unit, Functional & Fixture Tests (tests/Composer/): 62,410 lines across 318 files.

Subsystem Architecture: Decoupled Package & Solver Pipelines

Composer organizes its core codebase into decoupled domains under src/Composer/:

  1. DependencyResolver: The SAT solver core (Solver.php, RuleSet.php, RuleWatchGraph.php, Decisions.php, LockTransaction.php).
  2. Repository: Metadata repositories (ComposerRepository, PathRepository, VcsRepository, InstalledRepository).
  3. Autoload: PSR-0, PSR-4, classmap, and files autoloader generator (AutoloadGenerator.php, ClassLoader.php).
  4. Package: Package models, semantic version parsers, link constraints, and archive extractors (Package.php, Version/VersionParser.php).
  5. Console & IO: Symfony Console CLI integration, progress bars, and authenticating HTTP downloaders.

We ran prod-code dependencies across the codebase:

$ prod-code dependencies --scope modules
⚡ prod-code Architecture & Dependency Graph Report
────────────────────────────────────────────────────
Scope: modules | Nodes: 12 | Dependencies: 0

✓ Zero circular dependencies detected. Architecture graph is a clean DAG.

The captured run found 12 nodes and zero dependency edges. This incomplete result cannot establish a DAG, dependency direction, repository/solver independence, or architectural layering.

The Boolean Satisfiability (SAT) Solver

Unlike package managers that use naive greedy backtracking or heuristic depth-first search, Composer implements a Boolean Satisfiability solver based on openSUSE’s libsolv concepts.

In src/Composer/DependencyResolver/Solver.php (1,154 lines), version requirements and conflict statements are translated into boolean clauses (rules). Each rule represents a clause in Conjunctive Normal Form (CNF):

public function solve(Request $request, ?PlatformRequirementFilterInterface $filter = null): LockTransaction
{
    $this->setupFixedMap($request);

    $this->io->writeError('Generating rules', true, IOInterface::DEBUG);
    $ruleSetGenerator = new RuleSetGenerator($this->policy, $this->pool);
    $this->rules = $ruleSetGenerator->getRulesFor($request, $filter);
    
    $this->decisions = new Decisions($this->pool);
    $this->watchGraph = new RuleWatchGraph;

    foreach ($this->rules as $rule) {
        $this->watchGraph->insert(new RuleWatchNode($rule));
    }

    $this->makeAssertionRuleDecisions();

    $this->io->writeError('Resolving dependencies through SAT', true, IOInterface::DEBUG);
    $this->runSat();

    if (\count($this->problems) > 0) {
        throw new SolverProblemsException($this->problems, $this->learnedPool);
    }

    return new LockTransaction($this->pool, $request->getPresentMap(), $request->getFixedPackagesMap(), $this->decisions);
}

The resolution engine relies on key algorithmic components:

  • 2-Watched Literals (RuleWatchGraph.php): Inspired by modern SAT solvers like MiniSat, Composer watches two literals per ordinary rule. It is not two for every clause: in RuleWatchGraph.php at commit 43f74517, a comparison revision rather than the unrecorded checkout measured here, assertion rules get no watches and a MultiConflictRule watches all of its literals. When a variable is assigned false, only clauses watching that literal are examined, drastically reducing iteration overhead during clause propagation.
  • Unit Propagation (propagate()): As decisions are made, any clause reduced to a single unbound literal forces that literal to true.
  • Conflict Analysis & Learning: When a conflicting assignment is reached, Composer analyzes the implication graph, derives a learned clause that prunes the search space, and backtracks to the assertion level.
  • Clear Problem Diagnostics: If a solution cannot be found, SolverProblemsException explains the exact conflicting clauses to the user rather than failing with generic resolution errors.

Clone Analysis and Test Repetitions

We executed prod-code duplicates to detect structural cloning:

$ prod-code duplicates --min-lines 6 --max-groups 5
⚡ prod-code Clone & Duplication Harvester Report
────────────────────────────────────────────────────
Files Scanned: 633 | Lines: 139596 | Clone Groups: 5 | Duplication: 1.3%

Discovered Clone Groups:

[Clone Group #3661] 6 lines | 70 occurrences (Type-2 (Parameterized))
  • tests/Composer/Test/Json/JsonManipulatorTest.php:350-355
  • tests/Composer/Test/Json/JsonManipulatorTest.php:361-366
  • tests/Composer/Test/Json/JsonManipulatorTest.php:374-379
  • tests/Composer/Test/Json/JsonManipulatorTest.php:385-390
  • tests/Composer/Test/Json/JsonManipulatorTest.php:396-401
  Preview:
    │                     "require": {
    │                         "heroku-sys/php": ">=5.3.0"
    │                     },
    │                     "replace": [],

The report gives duplication across its 139,596 scanned lines as 1.3%. The one clone group it lists consists of repeated mock JSON manifests in tests/Composer/Test/Json/JsonManipulatorTest.php, where tests verify indentation preservation, key sorting, and whitespace hygiene during automated composer.json updates.

The shown clone report (capped at five groups) lists only that one test group, so it shows nothing either way about duplication inside src/Composer/.

Correction, 2026-10-27. As published on 2026-10-04, this section said core logic in src/Composer/ demonstrates high discipline. The cited evidence is a report run with --max-groups 5 that lists one group, in tests/; it scanned 633 files and 139,596 lines where the inventory above counts 634 files and 139,690 lines, and it does not show how the 1.3% was calculated. That supports the reported percentage and the one group shown, nothing more. The conclusion about the discipline of the production code is withdrawn.

Matching-Line Counts: 2,536 Assertion Lines and 620 Throw Lines

The article reports two grep matching-line counts:

$ grep -rnE "(self::assert|\$this->assert)" tests/ | wc -l
2536
$ grep -rnE "throw new " src/ | wc -l
620

As reported, 2,536 lines under tests/ match the assertion pattern and 620 lines under src/ contain throw new. These are counts of matching lines, not of assertions executed or exceptions thrown.

Correction, 2026-10-27. As published on 2026-10-04, this section said Composer enforces invariant guarantees and, from these two counts, rigorously checks package hash checksums, lock file consistency, JSON syntax validity and filesystem permission constraints. The commands above count lines that match a pattern; they say nothing about what those lines check or whether they run. The pattern also has a defect: inside the double quotes the shell turns \$this into $this, and under POSIX extended-regex rules an unescaped $ is an end-of-line anchor, so the $this->assert alternative cannot match a $this->assert… call and the 2,536 figure reflects only lines that match self::assert. The counts stand as reported; the invariant and checking claims are withdrawn.

Remote AST Operations on Cluster Nodes

We evaluated AST refactoring operations against Composer on the remote cluster node. Running prod-code extract-function on directory traversal and path normalization logic in src/Composer/Util/Filesystem.php completed in 12 milliseconds on the node, as the article reports. No selection, patch, diagnostics or local resource measurement is shown, so the operation and its timing are author-reported and unverified.

Correction, 2026-10-27. As published on 2026-10-04, this sentence said the extraction verified semantic references across the test suite without taxing local laptop resources. The article shows no command output, patch, analyzer or test result for this operation and no local measurement. The 12-millisecond figure is kept as reported; the verification and local-resource claims are withdrawn.

Composer demonstrates how mathematically sound algorithm design-specifically Boolean SAT with watched literals-can solve industrial-scale software distribution challenges in an interpreted language.

Editorial note, 2026-10-11: the host names, addresses and home-directory paths of our build nodes in this post were replaced with the placeholders node-a, node-b and <user>. No other part of the quoted output was changed.

Cite this article
Citation
Alexander Panasenko (2026-10-04). Composer Under the Microscope: What 67 Remote AST Tools Found Inside the PHP Dependency Manager. https://prod.codes/blog/composer-under-the-microscope-67-ast-tools/