PHPackages                             jbzoo/ci-report-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. jbzoo/ci-report-converter

ActiveLibrary[Testing &amp; Quality](/categories/testing)

jbzoo/ci-report-converter
=========================

The tool converts different error reporting standards for deep integration with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc)

7.2.3(7mo ago)30784.4k↓16.7%2[1 PRs](https://github.com/JBZoo/CI-Report-Converter/pulls)2MITPHPPHP ^8.2CI passing

Since Apr 26Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/JBZoo/CI-Report-Converter)[ Packagist](https://packagist.org/packages/jbzoo/ci-report-converter)[ RSS](/packages/jbzoo-ci-report-converter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (28)Used By (2)

JBZoo / CI-Report-Converter
===========================

[](#jbzoo--ci-report-converter)

[![CI](https://github.com/JBZoo/CI-Report-Converter/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/CI-Report-Converter/actions/workflows/main.yml?query=branch%3Amaster)[![Coverage Status](https://camo.githubusercontent.com/3ad141355cabef2789a4d18b23c009eb97f59ff76f6079cce30b8a180748eadf/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4a425a6f6f2f43492d5265706f72742d436f6e7665727465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/JBZoo/CI-Report-Converter?branch=master)[![Psalm Coverage](https://camo.githubusercontent.com/8e9d4a12da0dbe951d002951233c609ed341316c77664eb80affb371cdb610f9/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f43492d5265706f72742d436f6e7665727465722f636f7665726167652e737667)](https://shepherd.dev/github/JBZoo/CI-Report-Converter)[![Psalm Level](https://camo.githubusercontent.com/0b810cccf108671eb02b2ee4d85b16d91ff045d4d5ca2b3279cbab3a1cf4d108/68747470733a2f2f73686570686572642e6465762f6769746875622f4a425a6f6f2f43492d5265706f72742d436f6e7665727465722f6c6576656c2e737667)](https://shepherd.dev/github/JBZoo/CI-Report-Converter)[![CodeFactor](https://camo.githubusercontent.com/6e6c1fe34fce46281ac364761c4ee467d983d803971059dce74989a743014514/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f6a627a6f6f2f63692d7265706f72742d636f6e7665727465722f6261646765)](https://www.codefactor.io/repository/github/jbzoo/ci-report-converter/issues)

[![Stable Version](https://camo.githubusercontent.com/b85f7a2df907901449d4d0e371197c9c9811cb99f681ecc3e150fc8cbff491af/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f63692d7265706f72742d636f6e7665727465722f76657273696f6e)](https://packagist.org/packages/jbzoo/ci-report-converter/)[![Total Downloads](https://camo.githubusercontent.com/1699538b6cfb86b5732d30e9e4e1c0767d73b742c756ee04452426822bfd7d4c/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f63692d7265706f72742d636f6e7665727465722f646f776e6c6f616473)](https://packagist.org/packages/jbzoo/ci-report-converter/stats)[![Docker Pulls](https://camo.githubusercontent.com/8b2477af182b32a77792ad5d7f7d38fe743fb4efff31b9421069a591a13dcc11/68747470733a2f2f696d672e736869656c64732e696f2f646f636b65722f70756c6c732f6a627a6f6f2f63692d7265706f72742d636f6e7665727465722e737667)](https://hub.docker.com/r/jbzoo/ci-report-converter)[![Dependents](https://camo.githubusercontent.com/bb63157122944c60a0c6076c056ac6a31acd685a6d90bb8f0c740878cf6fcf46/68747470733a2f2f706f7365722e707567782e6f72672f6a627a6f6f2f63692d7265706f72742d636f6e7665727465722f646570656e64656e7473)](https://packagist.org/packages/jbzoo/ci-report-converter/dependents?order_by=downloads)[![GitHub License](https://camo.githubusercontent.com/51490b21fe23306a73824b8216902c6563d136e9ea25b5027cfd2bb111feac02/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a627a6f6f2f63692d7265706f72742d636f6e766572746572)](https://github.com/JBZoo/CI-Report-Converter/blob/master/LICENSE)

- [Why?](#why)
- [Installing](#installing)
- [Using as GitHub Action](#using-as-github-action)
    - [Example GitHub Action workflow](#example-github-action-workflow)
- [Available Directions](#available-directions)
- [Help description in terminal](#help-description-in-terminal)
    - [Converting](#converting)
    - [Custom Metrics in TeamCity](#custom-metrics-in-teamcity)
- [Examples](#examples)
    - [JetBrains IDE (IntelliJ IDEA, PhpStorm, WebStorm, etc)](#jetbrains-ide-intellij-idea-phpstorm-webstorm-etc)
        - [Mess Detector (phpmd-json)](#mess-detector-phpmd-json)
        - [Magic Number Detector (phpmnd)](#magic-number-detector-phpmnd)
        - [Copy/Paste Detector (pmd-cpd)](#copypaste-detector-pmd-cpd)
        - [PHPStan (checkstyle)](#phpstan-checkstyle)
        - [Psalm (psalm-json)](#psalm-psalm-json)
        - [Phan (checkstyle)](#phan-checkstyle)
    - [TeamCity - Style Issue As Failed Unit test](#teamcity---style-issue-as-failed-unit-test)
    - [TeamCity - Style Issue As Code Inspections](#teamcity---style-issue-as-code-inspections)
    - [TeamCity - Reported Statistic Values](#teamcity---reported-statistic-values)
    - [GitHub Actions](#github-actions)
    - [GitLab CI](#gitlab-ci)
    - [Use tool as SDK to generate reports](#use-tool-as-sdk-to-generate-reports)
        - [JUnit.xml (API)](#junitxml-api)
        - [GitHub Actions (API)](#github-actions-api)
- [Contributing](#contributing)
- [License](#license)
- [See Also](#see-also)

Why?
----

[](#why)

I believe you are familiar with the huge zoo of various utilities for testing, checking code standards, linters etc. It's really often the output of utilities is not supported in popular CI systems (TeamCity, GitHub, etc...). I guess you are lucky if the utility saves the error report in the `junit.xml` format, because it works pretty fine with almost all modern dev software.

But... My experience tells me it's the exception rather than the rule. For example, I really like the good old [phpmd](https://github.com/phpmd/phpmd) utility (perhaps you have another *right* opinion about the benefits. At least, it's just an example). It doesn't integrate well with TeamCity/PhpStorm/GitHub. Everytime I spend a lot of time looking for results in the logs. Though I really want to see instant and well-printed error report.

Therefore, I developed a converter that changes the report format for deep integration with CI systems and JetBrain IDEs.

Well... It may seem to you it's a useless thing, and *your favorite super tool* works fine in TeamCity/PhpStorm. Just take a look at [the examples below](#examples).

Requirements
------------

[](#requirements)

- PHP 8.2 or higher
- Extensions: dom, simplexml, hash

Installing
----------

[](#installing)

```
composer require jbzoo/ci-report-converter
php ./vendor/bin/ci-report-converter --help

# OR use phar file
wget https://github.com/JBZoo/CI-Report-Converter/releases/latest/download/ci-report-converter.phar
chmod +x ./ci-report-converter.phar
./ci-report-converter.phar --help

# OR just pull the Docker Image
docker run --rm jbzoo/ci-report-converter --help
```

Using as GitHub Action
----------------------

[](#using-as-github-action)

Action allows you to convert error reports to the [GitHub Annotations format](https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message)

- See [demo of error output](https://github.com/JBZoo/CI-Report-Converter/actions/workflows/gh-action.yml?query=is%3Asuccess)
- To learn more [see different examples](.github/workflows/gh-action.yml)

```
- uses: jbzoo/ci-report-converter@master # or see the specific version on releases page
  with:
    # File path with the original report format. If not set or empty, then the STDIN is used.
    # Required: true
    input-file: ./build/checkstyle.xml

    # Source format. Available options: checkstyle, junit, phpmd-json, phpmnd, pmd-cpd, psalm-json
    # Default value: checkstyle
    # Required: true
    input-format: checkstyle

    # Will exit with the code=1, if any violations are found.
    # Default value: no
    non-zero-code: yes

    # File path with the result report format. If not set or empty, then the STDOUT is used.
    output-file: ./build/junit.xml

    # Target format. Available options: gitlab-json, github-cli, junit, plain, tc-inspections, tc-tests
    # Default value: github-cli
    # Required: true
    output-format: junit

    # If option is set, all absolute file paths will be converted to relative once.
    # Default value: .
    root-path: ./custom/project/path

    # Set custom name of root group/suite (if it's possible).
    # Required: true
    suite-name: My Tests
```

### Example GitHub Action workflow

[](#example-github-action-workflow)

```
name: Linters

on:
  pull_request:
    branches:
      - "*"

jobs:
  linters:
    name: PHPcs
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 8.2
          tools: composer

      - name: Install Dependencies
        run: composer install

      - name: PHP Code Sniffer
        run: ./vendor/bin/phpcs --report=checkstyle --standard=PSR12 -q ./src > ./build/phpcs-checkstyle.xml

      - name: Converting checkstyle.xml to Github Annotations
        uses: jbzoo/ci-report-converter@master
        with:
          input-file: build/phpcs-checkstyle.xml
```

Available Directions
--------------------

[](#available-directions)

 ```
graph LR;
    checkstyle_src("CheckStyle.xml");
    ci-report-converter(("CI-ReportConverter"));
    github-cli_target("GitHub Actions - CLI");
    gitlab-json_target("GitLab - JSON");
    junit_src("JUnit.xml");
    junit_target("JUnit.xml");
    phpmd-json_src("PHPmd.json");
    phpmnd_src("PHPmnd.xml");
    plain_target("Plain Text");
    pmd-cpd_src("PmdCpd.xml");
    psalm-json_src("Psalm.json");
    tc-inspections_target("TeamCity - Inspections");
    tc-tests_target("TeamCity - Tests");

    checkstyle_src ==> ci-report-converter;
    ci-report-converter ==> github-cli_target;
    ci-report-converter ==> gitlab-json_target;
    ci-report-converter ==> junit_target;
    ci-report-converter ==> plain_target;
    ci-report-converter ==> tc-inspections_target;
    ci-report-converter ==> tc-tests_target;
    junit_src ==> ci-report-converter;
    phpmd-json_src ==> ci-report-converter;
    phpmnd_src ==> ci-report-converter;
    pmd-cpd_src ==> ci-report-converter;
    psalm-json_src ==> ci-report-converter;

linkStyle default interpolate basis;
```

      Loading At the moment, converting of reports works with

- Input Formats:
    - [checkstyle](tests/fixtures/origin/phpcs/codestyle.xml) - the most popular sort of error report. It works for [Phan](https://github.com/phan/phan), [PHPcs](https://github.com/squizlabs/PHP_CodeSniffer) and others.
    - [junit](tests/fixtures/origin/phpunit/junit-simple.xml) - also it's really popular sort of error report. Usually, the format is used to display unit test results.
    - [phpmd-json](tests/fixtures/origin/phpmd/json.json) - the most detailed report of [PHPMD](https://github.com/phpmd/phpmd).
    - [phpmnd](tests/fixtures/origin/phpmnd/phpmnd.xml) - I know only [PHP Magic Numbers Detector](https://github.com/povils/phpmnd).
    - [psalm-json](tests/fixtures/origin/psalm/json.json) - the most detailed report of [Psalm](https://github.com/vimeo/psalm).
    - [pmd-cpd](tests/fixtures/origin/phpcpd/pmd-cpd.xml) - it's PMD-CPD XML format. An example of tool is [Copy/Paste Detector](https://github.com/sebastianbergmann/phpcpd).
- Output Formats:
    - [gitlab-json](tests/fixtures/origin/phpstan/gitlab.json) - [GitLab Custom Report](https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html#implementing-a-custom-tool).
    - [junit](tests/fixtures/origin/phpunit/junit-simple.xml) - The most popular sort of reporting.
    - [tc-tests](tests/fixtures/test-cases/ConverterTeamCityTest/testJUnit.txt) - [Reporting Tests in TeamCity/PhpStorm/JetBrains](https://www.jetbrains.com/help/teamcity/service-messages.html#Reporting+Tests).
    - [tc-inspections](tests/fixtures/test-cases/ConverterTeamCityInspectionsTest) - [Reporting Inspections in TeamCity](https://www.jetbrains.com/help/teamcity/service-messages.html#Reporting+Inspections).

Also, you can follow [metrics around your code in TeamCity](https://www.jetbrains.com/help/teamcity/service-messages.html#Reporting+Build+Statistics) via `teamcity:stats`

- [JUnit.xml](tests/fixtures/origin/phpunit/junit-nested.xml) =&gt; [Example in TeamCity](tests/fixtures/test-cases/ConverterTeamCityStatsTest/testJUnitXml.txt)
- [PHPUnitClover.xml](tests/fixtures/origin/phpunit/clover.xml) =&gt; [Example in TeamCity](tests/fixtures/test-cases/ConverterTeamCityStatsTest/testPhpUnitCloverXml.txt)
- [PHPDepend.xml](tests/fixtures/origin/pdepend/pdepend-old.xml) =&gt; [Example in TeamCity](tests/fixtures/test-cases/ConverterTeamCityStatsTest/testPhpDependXml.txt)
- [PHPloc.json](tests/fixtures/origin/phploc/json.json) =&gt; [Example in TeamCity](tests/fixtures/test-cases/ConverterTeamCityStatsTest/testPhpLocJson.txt)
- [PHPMetrics.xml](tests/fixtures/origin/phpmetrics/phpmetrics.xml) =&gt; [Example in TeamCity](tests/fixtures/test-cases/ConverterTeamCityStatsTest/testPhpMetricsXml.txt)

Help description in terminal
----------------------------

[](#help-description-in-terminal)

### Converting

[](#converting)

```
$ php ./vendor/bin/ci-report-converter convert --help
Description:
  Convert one report format to another one

Usage:
  convert [options]

Options:
  -S, --input-format=INPUT-FORMAT      Source format. Available options: checkstyle, junit, phpmd-json, phpmnd, pmd-cpd, psalm-json [default: "checkstyle"]
  -I, --input-file[=INPUT-FILE]        File path with the original report format. If not set or empty, then the STDIN is used.
  -T, --output-format=OUTPUT-FORMAT    Target format. Available options: gitlab-json, github-cli, junit, plain, tc-inspections, tc-tests [default: "tc-tests"]
  -O, --output-file[=OUTPUT-FILE]      File path with the result report format. If not set or empty, then the STDOUT is used.
  -R, --root-path[=ROOT-PATH]          If option is set, all absolute file paths will be converted to relative once. [default: "."]
  -N, --suite-name=SUITE-NAME          Set custom name of root group/suite (if it's possible).
  -F, --tc-flow-id[=TC-FLOW-ID]        Custom flowId in TeamCity output. Default value is PID of the tool.
  -Q, --non-zero-code[=NON-ZERO-CODE]  Will exit with the code=1, if any violations are found. [default: "no"]
      --no-progress                    Disable progress bar animation for logs. It will be used only for text output format.
      --mute-errors                    Mute any sort of errors. So exit code will be always "0" (if it's possible).
                                       It has major priority then --non-zero-on-error. It's on your own risk!
      --stdout-only                    For any errors messages application will use StdOut instead of StdErr. It's on your own risk!
      --non-zero-on-error              None-zero exit code on any StdErr message.
      --timestamp                      Show timestamp at the beginning of each message.It will be used only for text output format.
      --profile                        Display timing and memory usage information.
      --output-mode=OUTPUT-MODE        Output format. Available options:
                                       text - Default text output format, userfriendly and easy to read.
                                       cron - Shortcut for crontab. It's basically focused on human-readable logs output.
                                       It's combination of --timestamp --profile --stdout-only --no-progress -vv.
                                       logstash - Logstash output format, for integration with ELK stack.
                                        [default: "text"]
      --cron                           Alias for --output-mode=cron. Deprecated!
  -h, --help                           Display help for the given command. When no command is given display help for the list command
      --silent                         Do not output any message
  -q, --quiet                          Only errors are displayed. All other output is suppressed
  -V, --version                        Display this application version
      --ansi|--no-ansi                 Force (or disable --no-ansi) ANSI output
  -n, --no-interaction                 Do not ask any interactive question
  -v|vv|vvv, --verbose                 Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

```

### Custom Metrics in TeamCity

[](#custom-metrics-in-teamcity)

To clarify the use of the method, take a look at the [examples and screenshots](#teamcity---reported-statistic-values) below, please.

```
$ php ./vendor/bin/ci-report-converter teamcity:stats --help
Description:
  Push code metrics to TeamCity Stats

Usage:
  teamcity:stats [options]

Options:
  -S, --input-format=INPUT-FORMAT  Source format. Available options: junit-xml, pdepend-xml, phploc-json, phpmetrics-xml, phpunit-clover-xml
  -I, --input-file[=INPUT-FILE]    File path with the original report format. If not set or empty, then the STDIN is used.
  -O, --output-file[=OUTPUT-FILE]  File path with the result report format. If not set or empty, then the STDOUT is used.
  -R, --root-path[=ROOT-PATH]      If option is set, all absolute file paths will be converted to relative once. [default: "."]
  -F, --tc-flow-id[=TC-FLOW-ID]    Custom flowId in TeamCity output. Default value is PID of the tool.
      --no-progress                Disable progress bar animation for logs. It will be used only for text output format.
      --mute-errors                Mute any sort of errors. So exit code will be always "0" (if it's possible).
                                   It has major priority then --non-zero-on-error. It's on your own risk!
      --stdout-only                For any errors messages application will use StdOut instead of StdErr. It's on your own risk!
      --non-zero-on-error          None-zero exit code on any StdErr message.
      --timestamp                  Show timestamp at the beginning of each message.It will be used only for text output format.
      --profile                    Display timing and memory usage information.
      --output-mode=OUTPUT-MODE    Output format. Available options:
                                   text - Default text output format, userfriendly and easy to read.
                                   cron - Shortcut for crontab. It's basically focused on human-readable logs output.
                                   It's combination of --timestamp --profile --stdout-only --no-progress -vv.
                                   logstash - Logstash output format, for integration with ELK stack.
                                    [default: "text"]
      --cron                       Alias for --output-mode=cron. Deprecated!
  -h, --help                       Display help for the given command. When no command is given display help for the list command
      --silent                     Do not output any message
  -q, --quiet                      Only errors are displayed. All other output is suppressed
  -V, --version                    Display this application version
      --ansi|--no-ansi             Force (or disable --no-ansi) ANSI output
  -n, --no-interaction             Do not ask any interactive question
  -v|vv|vvv, --verbose             Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

```

Examples
--------

[](#examples)

### JetBrains IDE (IntelliJ IDEA, PhpStorm, WebStorm, etc)

[](#jetbrains-ide-intellij-idea-phpstorm-webstorm-etc)

One of the unique features of the tool is converting reports to a unit test format compatible with JetBrains IDE and TeamCity. The following examples show how to use JetBrains IDE UI to display any kind of style issues. Yeah, I know that the integration is not the cleanest, and it's not super beautiful. However, this code/screenshots demonstrate the usability of the approach.

[![PHPcs in JetBrains PhpStorm](.github/assets/phpstorm-checkstyle.png)](.github/assets/phpstorm-checkstyle.png)

**NOTE:** I believe that coding style issues have the same level of severity as any other sort of errors. Therefore, I prefer to use the same workflow to check the quality of the code as I do with regular PHPUnit tests. It's like "just one click!" Also, you will have the awesome bonus - navigating the project and gives the most detailed information about errors.

**The general idea is pretty simple:**

- We take almost any utility for testing.
- It saves report in the file or outputs error to StdOut as xml/json.
- CI-Report-Converter changes the report format. It saves result somewhere or just outputs it in StdOut.
- ???
- Profit.

In the next example we will see how to integrate JetBrains IDE UI with Code Sniffer deeply. I use PHPcs just as example. This is the most popular linter in PHP. However, the approach is independent of the programming language or unit testing framework.

```
