Skip to content

PHPLint Converter

overtrue/phplint - GitHub

Note

Available since version 1.0.0

Table Of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. How to customize your converter
  5. Learn more
  6. IDE Integration

phplint converter

Requirements

  • PHPLint requires PHP version 8.1.0 or greater
  • This SARIF converter requires at least PHPLint version 9.4.0

Installation

composer require --dev overtrue/phplint bartlett/sarif-php-converters

Usage

vendor/bin/phplint --format='\Overtrue\PHPLint\Output\SarifOutput' /path/to/source/code

Warning

If you have the following error

Could not load sarif converter class: "Bartlett\Sarif\Converter\PhpLintConverter"

That means you've not specified the correct autoloader. Please use the --bootstrap run option of PHPLint like that:

vendor/bin/phplint --format='\Overtrue\PHPLint\Output\SarifOutput' --bootstrap=vendor/autoload.php

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 !

Tip

  • Without verbose option (-v) the PHPLint SarifOutput will print a compact SARIF version.

Step 1: Prints the SARIF report

vendor/bin/phplint --format='\Overtrue\PHPLint\Output\SarifOutput' --bootstrap vendor/autoload.php --output=examples/phplint/.sarif.json -v /path/to/source/code

(optional) Use the Console Tool as alternative

If you prefer to convert from a format supported natively by PHPLint, then :

Step 1: Build the native checkstyle output report

vendor/bin/phplint --format=checkstyle --output=checkstyle.xml /path/to/source/code

Step 2: And finally, convert it to SARIF with the Console Tool

php report-converter convert phplint --input-format=checkstyle --input-file=examples/phplint/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

IDE Integration

The SARIF report file [*].sarif.json is automagically recognized and interpreted by PhpStorm (2024).

PHPStorm integration