PHP-CS-Fixer Converter
Note
Available since version 1.0.0
Table Of Contents
Requirements
- PHP-CS-Fixer requires PHP version 7.4.0 or greater, with
filter
,json
andtokenizer
extensions loaded - This SARIF converter requires at least PHP-CS-Fixer version 3.5.0
Installation
composer require --dev php-cs-fixer/php-cs-fixer bartlett/sarif-php-converters
Usage
Warning
As PHP-CS-Fixer is not able to register custom reporter, we have no other alternative that using the Console Tool convert command.
Step 1: Build the native checkstyle output report
vendor/bin/php-cs-fixer fix --dry-run --format checkstyle /path/to/source/code > checkstyle.xml
Warning
Be sure to specify absolute path to source code to analyze, otherwise the Console Tool convert
command
will raise some warnings about file names.
Step 2: And finally, convert it to SARIF with the Console Tool
php report-converter convert phpcs-fixer --input-format=checkstyle --input-file=examples/phpcs-fixer/checkstyle.xml -v
Tip
- Without verbose option (
-v
) the Console Tool will print a compact SARIF version. --output-file
option allows to write a copy of the report to a file. By default, the Console Tool will always print the specified report to the standard output.
Learn more
- See demo
examples/php-cs-fixer/
directory into this repository.
IDE Integration
The SARIF report file [*].sarif.json
is automagically recognized and interpreted by PhpStorm (2024).
Web SARIF viewer
With the React based component, you are able to explore a sarif report file previously generated.
For example: