Surface PHP errors, PHPUnit failures, and static analysis warnings as inline annotations in GitHub pull requests using problem matchers.
Problem matchers are JSON configuration files that tell GitHub Actions how to parse tool output and surface errors and warnings as inline annotations directly in pull requests and workflow run logs. They map log patterns to file paths and line numbers so reviewers can see issues without leaving the diff.setup-php ships problem matcher files for PHP and PHPUnit inside the runner’s tool cache. Additional tools like PHPStan and Psalm have native GitHub Actions output formats that work without a separate matcher file.
The PHP problem matcher catches fatal errors, parse errors, and warnings in PHP output and links them to the corresponding source file and line.Add this step immediately after the setup-php step:
- name: Setup problem matchers for PHP run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
The PHPUnit problem matcher highlights failing test cases in the workflow run log and annotates the test file at the failing assertion’s line number.Add this step after the setup-php step, before you run your tests:
- name: Setup problem matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
You can activate both matchers in a single workflow to get annotations for both PHP runtime errors and PHPUnit failures.
PHPStan has native GitHub Actions support built in. When it detects that it is running inside GitHub Actions it automatically emits annotations without requiring a problem matcher. No additional configuration is needed.
Several PHP tools can emit results in the checkstyle XML format: phpcs, phpstan, psalm, and php-cs-fixer. You can pipe that output into cs2pr, which converts checkstyle XML into GitHub Actions annotations.Install cs2pr via the tools input and pipe checkstyle output to it:
cs2pr exits with a non-zero status code when it finds issues, which causes the workflow step to fail as expected. Refer to the cs2pr documentation for additional options such as filtering by severity or graceful-warnings mode.