Hamburger Cross Icon
PHP Collector - Lunar Collector

PHP Collector

Collector Beta LanguagesBuild

Analyze PHP projects to collect Composer metadata, dependencies, tool configuration (PHPUnit, PHPStan, Psalm, PHP-CS-Fixer, PHPCS), and CI/CD command tracking. Enforce PHP-specific engineering standards.

Add php to your lunar-config.yml:
uses: github://earthly/lunar-lib/collectors/php@v1.0.0

What This Integration Collects

This integration includes 5 collectors that gather metadata from your systems.

Collector ci-before-command

cicd

Records every PHP command executed in CI pipelines along with the PHP runtime version. Writes command strings and version info to .lang.php.cicd for audit trails and build reproducibility analysis.

php ci php version ci commands build tracking
Book a demo
Collector ci-before-command

composer-cicd

Records every Composer command executed in CI pipelines along with the Composer version. Writes command strings and version info to .lang.php.composer.cicd for audit trails and dependency management.

composer ci composer version ci commands dependency management
Book a demo
Collector code

project

Analyzes PHP project structure by detecting composer.json, composer.lock, vendor directory, and tool configuration (PHPUnit, PHPStan, Psalm, PHP-CS-Fixer, PHP_CodeSniffer). Extracts the PHP version constraint. Writes PHP-level metadata to .lang.php and Composer metadata to .lang.php.composer.

php project composer.json project structure phpunit phpstan
Book a demo
Collector code

dependencies

Extracts direct and dev dependencies from composer.json. Captures package name and version constraint for each dependency. Writes the dependency list to .lang.php.dependencies.

php dependencies composer supply chain packages
Book a demo
Collector ci-after-command

test-coverage

Extracts test coverage percentage from PHPUnit's Clover XML output after tests complete. Parses coverage-clover report and writes results to .lang.php.tests.coverage.

code coverage phpunit coverage clover coverage metrics
Book a demo

How Collectors Fit into Lunar

Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.

Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.

Learn How Lunar Works
1
Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "lang": {
    "php": {
      "version": "^8.2",
      "build_systems": ["composer"],
      "phpunit_configured": true,
      "static_analysis_configured": true,
      "static_analysis_tool": "phpstan",
      "code_style_configured": true,
      "code_style_tool": "php-cs-fixer",
      "source": { "tool": "php", "integration": "code" },
      "cicd": {
        "cmds": [
          { "cmd": "php artisan migrate", "version": "8.2.15" }
        ]
      },
      "dependencies": {
        "direct": [
          { "path": "laravel/framework", "version": "^11.0" }
        ],
        "dev": [
          { "path": "phpunit/phpunit", "version": "^11.0" }
        ],
        "source": { "tool": "composer", "integration": "code" }
      },
      "composer": {
        "json_exists": true,
        "lock_exists": true,
        "vendor_exists": false,
        "cicd": {
          "cmds": [
            { "cmd": "composer install --no-dev", "version": "2.7.1" }
          ]
        }
      }
    }
  }
}

Configuration

Configure this collector in your lunar-config.yml.

Inputs

Input Required Default Description

Documentation

View on GitHub

PHP Collector

Collects PHP project information, CI/CD commands, and dependencies.

Overview

This collector gathers metadata about PHP projects including Composer configuration, dependency graphs, tool configuration (PHPUnit, PHPStan, Psalm, PHP-CS-Fixer, PHP_CodeSniffer), and CI/CD command tracking. It runs on both code changes (for static analysis) and CI hooks (to capture runtime metrics).

Collected Data

This collector writes to the following Component JSON paths:

Path Type Description
.lang.php object PHP project metadata (version, tool config)
.lang.php.version string PHP version constraint from composer.json
.lang.php.cicd object PHP runtime CI/CD command tracking with version
.lang.php.dependencies object Direct and dev dependencies from composer.json
.lang.php.composer object Composer metadata (json/lock exists, vendor, cicd)
.lang.php.composer.cicd object Composer CI/CD command tracking with version
.lang.php.tests.coverage object Test coverage metrics from PHPUnit Clover XML output

Collectors

This integration provides the following collectors (use include to select a subset):

Collector Hook Type Description
project code Collects PHP project structure (composer.json, composer.lock, vendor, tool config)
dependencies code Collects Composer dependency graph
cicd ci-before-command Tracks PHP commands run in CI with PHP runtime version
composer-cicd ci-before-command Tracks Composer commands run in CI with Composer version
test-coverage ci-after-command Extracts coverage from PHPUnit Clover XML reports

Installation

Add to your lunar-config.yml:

collectors:
  - uses: github://earthly/lunar-lib/collectors/php@v1.0.0
    on: [php]  # Or use domain: ["domain:your-domain"]
    # include: [project, dependencies]  # Only include specific subcollectors

Open Source

This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

Ready to Automate Your Standards?

See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.

Works with any process
check Infrastructure conventions
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Automate Now
Turn any process doc into guardrails
Book a Demo