Twig-CS-Fixer Converter
Note
Available since version 1.0.0
Table Of Contents
Requirements
- Twig-CS-Fixer requires PHP version 8.0 or greater, with
ctypeandjsonextensions loaded - This SARIF converter requires at least Twig-CS-Fixer version 3.0.0
Installation
Usage
Tip
The .twig-cs-fixer.dist.php config file should at least identify the default Custom Reporter class TwigCsFixerReporter
How to customize your converter
There are many ways to customize render of your converter.
Make the SARIF report output human-readable
By default, all converters use the default \Bartlett\Sarif\Factory\PhpSerializerFactory
to return the SARIF JSON representation of your report.
But this serializer factory component, as native PHP json_encode function,
does not use whitespace in returned data to format it.
To make your report human-readable, you have to specify the \JSON_PRETTY_PRINT constant, as encoder option.
Here is the way to do it !
Create your report specialized class
<?php
use Bartlett\Sarif\Converter\Reporter\TwigCsFixerReporter;
use Bartlett\Sarif\Converter\TwigCsFixerConverter;
class MyTwigCsFixerReporter extends TwigCsFixerReporter
{
public function __construct()
{
// enable pretty print feature
parent::__construct(
new TwigCsFixerConverter([
'format_output' => true,
])
);
}
}
And finally, print the SARIF report
Tip
The MyTwigCsFixerReporter class is identified by the .twig-cs-fixer.php config file.
(optional) Use the Console Tool as alternative
If you prefer to convert from a [format supported natively][[twigcs-fixer-custom-reporters]] by Twig-CS-Fixer, then :
Build the checkstyle output report
And finally, convert it to SARIF with the Console Tool
php report-converter convert twigcs-fixer --input-format=checkstyle --input-file=examples/twigcs-fixer/checkstyle.xml -v
Tip
- Without verbose option (
-v) the Console Tool will print a compact SARIF version. --output-fileoption 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/twigcs-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:
