From d8ef848af621d3ab7800432792658e504eed91da Mon Sep 17 00:00:00 2001 From: Oleh Vehera <11544787+iVegas@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:14:54 +0200 Subject: [PATCH 1/2] feat: add documentation for custom report types in PHP_CodeSniffer Added a section on using custom report types with PHP_CodeSniffer, including how to create and implement a custom report class. --- wiki/Reporting.md | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/wiki/Reporting.md b/wiki/Reporting.md index 142cbbd..3eee518 100644 --- a/wiki/Reporting.md +++ b/wiki/Reporting.md @@ -21,6 +21,7 @@ * [Running Interactively](#running-interactively) * [Specifying a Report Width](#specifying-a-report-width) * [Writing a Report to a File](#writing-a-report-to-a-file) +* [Using Custom Report Types](#using-custom-report-types) *** @@ -570,3 +571,81 @@ $ phpcs --report=xml --report-file=/path/to/file.xml /path/to/code > The report will not be written to the screen when using this option. If you still want to view the report, use the -v command line argument to print verbose output.

back to top

+ +## Using Custom Report Types + +In addition to the built-in report types, PHP_CodeSniffer supports +custom report types provided by external packages. A custom report is a +PHP class that implements the `PHP_CodeSniffer\Reports\Report` interface. + +### Using a custom report from a coding standard + +If a coding standard ships a custom report class, ensure the standard is +installed (e.g. via Composer) and reference the report using its +**fully-qualified class name**: + +``` +$ phpcs --report=My\\Standard\\Reports\\Sonarqube /path/to/code +``` + +When using the `--report-[type]` syntax for multiple reports, replace +back­slashes with periods: + +``` +$ phpcs --report-full --report-My.Standard.Reports.Sonarqube=/path/to/sonarqube.json /path/to/code +``` + +### Creating a custom report + +To create your own custom report, implement the +`PHP_CodeSniffer\Reports\Report` interface. The interface requires two +methods: + +| Method | Purpose | +|---|---| +| `generateFileReport()` | Called once per file. Print/accumulate partial output and return `TRUE` if the file contained reportable messages, `FALSE` otherwise. | +| `generate()` | Called once after all files are processed. Receives the cached data from `generateFileReport()` calls and is responsible for producing the final output. | + +A minimal custom report class looks like this: + +```php + **Tip:** See the built-in +> [Json](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/src/Reports/Json.php) +> report for a complete reference implementation. + +

back to top

From 159cecf3e297db6a20e6b6ea40c7c4c485d89361 Mon Sep 17 00:00:00 2001 From: Oleh Vehera <11544787+iVegas@users.noreply.github.com> Date: Mon, 16 Mar 2026 13:24:31 +0200 Subject: [PATCH 2/2] fix: code block formatting in Reporting.md Correct formatting for report command examples. --- wiki/Reporting.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wiki/Reporting.md b/wiki/Reporting.md index 3eee518..f3b0418 100644 --- a/wiki/Reporting.md +++ b/wiki/Reporting.md @@ -584,14 +584,15 @@ If a coding standard ships a custom report class, ensure the standard is installed (e.g. via Composer) and reference the report using its **fully-qualified class name**: -``` + +```bash $ phpcs --report=My\\Standard\\Reports\\Sonarqube /path/to/code ``` When using the `--report-[type]` syntax for multiple reports, replace back­slashes with periods: -``` +```bash $ phpcs --report-full --report-My.Standard.Reports.Sonarqube=/path/to/sonarqube.json /path/to/code ```