Skip to content

PHPMD Converter

phpmd/phpmd - GitHub

Note

Available since version 1.0.0

Table Of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. Learn more
  5. IDE Integration
  6. Web SARIF viewer

phpmd converter

Requirements

  • PHP Mess Detector version 2.0 requires PHP version 5.3.9 or greater, with xml extensions loaded
  • PHP Mess Detector version 3.0 requires PHP version 8.1 or greater, with xml extensions loaded

The Bartlett\Sarif\Converter\Reporter\PhpMdRenderer class is ready to use the new feature : Simplify load of external custom renderer available into PHPMD version 3.0

Installation

composer require --dev phpmd/phpmd bartlett/sarif-php-converters

Usage

Warning

  • As PHMMD v2.15 is not able to specify/boot custom renderer easily, we have no other alternative that using the Console Tool convert command.

  • With PHPMD v3.0 is easier. Use the alternative solution at step 3.

Build the checkstyle output report

vendor/bin/phpmd /path/to/source checkstyle ruleset --report-file=checkstyle.xml

And finally, convert it to SARIF with the Console Tool

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

Alternative usage

Build the sarif output report directly via the default Bartlett\Sarif\Converter\Reporter\PhpMdRenderer

vendor/bin/phpmd analyze /path/to/source --format='\Bartlett\Sarif\Converter\Reporter\PhpMdRenderer' --bootstrap=autoload.php > sarif.json

Tip

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

Learn more

IDE Integration

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

PHPStorm integration

Web SARIF viewer

With the React based component, you are able to explore a sarif report file previously generated.

For example:

sarif-web-phpmd