Download the PHP package sebastiaanwouters/diffalyzer without Composer

On this page you can find all versions of the php package sebastiaanwouters/diffalyzer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package diffalyzer

Diffalyzer

Latest Stable Version Total Downloads License PHP Version

A PHP CLI tool that analyzes git changes and outputs affected PHP file paths in formats compatible with PHPUnit, Psalm, ECS, and PHP-CS-Fixer. This enables optimized test and analysis runs by only processing files that are actually affected by changes.

Features

Installation

Via Composer (Recommended)

After installation, the binary will be available at vendor/bin/diffalyzer.

From Source

Quick Start

Usage

Basic Usage

With Strategies

Git Comparison Options

Full Scan Pattern

Full-scan patterns can be configured via config file (recommended) or CLI flag:

Via config file (recommended):

Via CLI flag (overrides config):

Note: Always use --verbose to see:

Integration Examples

PHPUnit

Psalm

ECS (Easy Coding Standard)

PHP-CS-Fixer

Command Line Options

Option Short Description Default
--output -o Output format: test (test files only) or files (all files) Required
--strategy -s Analysis strategy: conservative, moderate, minimal conservative
--from Source ref for comparison (branch or commit hash)
--to Target ref for comparison (branch or commit hash) HEAD
--staged Only analyze staged files false
--full-scan-pattern Regex (e.g., /\.xml$/) or glob pattern (e.g., *.xml) to trigger full scan (overrides config)
--config -c Path to config file Auto-detect
--verbose -v Show detailed diagnostic information (outputs to stderr) false
--test-pattern Custom regex pattern to match test files
--no-cache Disable cache and force full rebuild false
--clear-cache Clear cache before analysis false
--cache-stats Show cache statistics after analysis false
--parallel -p Number of parallel workers for parsing Auto-detect

Configuration File

Diffalyzer supports configuration files to centralize settings like full-scan patterns. Configuration files are automatically detected in the following order:

  1. .diffalyzer.yml
  2. diffalyzer.yml
  3. config.yml

Or specify a custom path with --config path/to/config.yml.

Example Configuration

Pattern Types

Glob patterns (recommended for simplicity):

Regex patterns (for advanced matching):

Complete Override Behavior

When you define patterns in your config file, they completely replace the built-in defaults:

To disable full scans entirely:

Verbose Mode

Use --verbose (or -v) to see detailed diagnostic information about what diffalyzer is doing:

Verbose output (sent to stderr, won't interfere with stdout):

Or when full scan is triggered:

This makes it much clearer what's happening, especially when you get empty output (which means "run on all files").

Analysis Strategies

Conservative (Default)

Includes all dependency types:

Most comprehensive but may include some false positives.

Moderate

Includes:

Excludes dynamic method calls and instantiations.

Minimal

Includes only:

Fastest but may miss some affected files.

Output Behavior

Partial Scan (Normal Mode)

--output test

Outputs space-separated test file paths that are affected by the changes.

How it works: The tool uses AST-based dependency analysis to find ALL test files that import or use the affected classes. It does NOT assume file naming conventions or directory structures.

Test Method Filtering (New in v1.2.0): Diffalyzer now supports the :: syntax for specifying individual test methods. When you pass file paths with ::methodName, diffalyzer automatically converts them to PHPUnit's --filter syntax:

This provides an intuitive, framework-agnostic syntax for running specific test methods without needing to remember PHPUnit's --filter syntax.

Examples:

  1. Test files that import changed classes

    • src/User.php changes (declares Diffalyzer\User)
    • tests/UserTest.php imports Diffalyzer\Userincluded in output
    • Works regardless of file names or directory structure
  2. Transitive dependencies

    • src/User.php changes
    • src/UserCollector.php imports/uses User → affected
    • tests/UserCollectorTest.php imports UserCollectorincluded in output
    • Full dependency chain is traversed automatically
  3. Test files that changed directly

    • tests/UserTest.php modified → included in output
  4. No assumptions about structure

    • Works with tests/, test/, Tests/, Test/, or any directory
    • Works with any test file naming convention (as long as it contains "Test.php")
    • Works with custom project structures
  5. Data fixtures via PHP classes
    • If tests use fixture/factory classes (e.g., UserFixture, UserFactory)
    • Changes to those fixture classes are tracked via normal dependency analysis
    • When UserFixture.php changes → tests importing it are included
    • No special configuration needed

Example output: tests/UserTest.php tests/UserCollectorTest.php tests/Integration/UserFlowTest.php

--output files

Outputs space-separated file paths for all affected files (includes both source and test files).

Use this for static analysis tools (Psalm), code style checkers (ECS, PHP-CS-Fixer), or any tool that needs to process all affected files.

Example output: src/Foo/Bar.php src/Baz/Qux.php tests/FooTest.php

Full Scan Mode

When full-scan patterns match or no specific files are needed:

Full Scan Triggers:

By default (when no config file is present), these files trigger full scans:

You can customize this behavior in three ways:

  1. Config file (recommended): Define patterns in diffalyzer.yml - replaces built-in defaults
  2. CLI flag: Use --full-scan-pattern - overrides config and built-in defaults
  3. Disable entirely: Set full_scan_patterns: [] in config

Understanding Empty Output:

Empty output is intentional and can mean two things:

  1. No changes detected - No PHP files were modified
  2. Full scan triggered - A file matched a full-scan pattern

Use --verbose to see which one:

How It Works

  1. Git Change Detection: Detects changed PHP files using git diff
  2. AST Parsing: Parses all project PHP files using nikic/php-parser
  3. Dependency Graph: Builds forward and reverse dependency maps
  4. Impact Analysis: Traverses graph to find all affected files
  5. Format Output: Generates tool-specific output format

Example Workflow

Step 1: Git detects changes

Step 2: Dependency analysis

Step 3: Output by format

For --output files (all source files):

For --output test (test files only):

Result: Run only the 3 tests affected by the User.php change, not all 100+ tests in your suite!

Advanced Integration

Makefile

Use the included Makefile for convenient local development:

Pre-commit Hook

Create .git/hooks/pre-commit:

Make it executable:

Composer Scripts

Add to your composer.json:

Then run:

CI/CD Integration

GitHub Actions

See .github/workflows/ci-example.yml for a complete working example. Basic setup:

GitLab CI

See .gitlab-ci-example.yml for a complete working example. Basic setup:

Troubleshooting

Full-scan pattern not working

Problem: Using --full-scan-pattern but full scan is not triggered.

Solutions:

  1. Use --verbose to debug: This will show you:

    • Which files actually changed
    • Which pattern is being used
    • Whether the pattern matched
    • Whether full scan was triggered
  2. Check pattern syntax:

    • Regex patterns must start with / or #: /\.xml$/, /^config\//
    • Glob patterns don't need delimiters: *.xml, phpunit.xml, config/**
    • When in doubt, use glob patterns (simpler and more intuitive)
  3. Verify the pattern matches your changed files:

  4. Common pattern examples:

  5. Pattern doesn't match subdirectories?
    • For glob: use config/** not config/* for recursive matching
    • For regex: use /^config\// to match anything starting with config/

No tests run but I made changes

Cause: You changed a file that no tests depend on.

Solutions:

All tests run when I change one file

Cause: Full scan was triggered.

Solutions:

Git errors

Cause: Not in a git repository or no commits exist.

Solutions:

Empty output

This is normal behavior and means:

Always handle empty output by running the full tool:

Tips & Best Practices

  1. Use Makefile: Convenient shortcuts for common operations
  2. CI/CD Branch Comparison: Use --from origin/main in pipelines
  3. Start Conservative: Begin with conservative strategy, optimize later if needed
  4. Fixture Classes: Modern fixtures (PHP classes) are automatically tracked
  5. Pre-commit Hooks: Use --staged flag for pre-commit validation
  6. Full Scan Patterns: Add critical config files to trigger complete scans
  7. Test Imports: Ensure test files import the classes they test for proper tracking
  8. Git History: Use fetch-depth: 0 in CI to enable proper branch comparison

Requirements

PHP Version Support

Diffalyzer supports the following PHP versions:

PHP Version Status Tested
8.1 ✅ Supported ✅ Yes
8.2 ✅ Supported ✅ Yes
8.3 ✅ Supported ✅ Yes
8.4 ✅ Supported ✅ Yes
8.0 or lower ❌ Not supported -

All versions are actively tested in CI/CD with both prefer-lowest and prefer-stable dependency strategies.

Other Requirements

Dependencies

License

MIT

Author

Created by Sebastiaan Wouters for optimized PHP testing and analysis workflows.


All versions of diffalyzer with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
nikic/php-parser Version ^5.0
symfony/console Version ^6.4 || ^7.0
symfony/process Version ^6.4 || ^7.0
symfony/finder Version ^6.4 || ^7.0
symfony/yaml Version ^6.4 || ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sebastiaanwouters/diffalyzer contains the following files

Loading the files please wait ...