Skip to content

checkstyle error formatter cuts the path to file when remote interpreter used for the run #3579

Description

@isfedorov

When I run PhpStan using remote php interpreter (from Docker for example) with --error-format=checkstyle option, path to problematic file in the output is cut from the head.

Steps to reproduce:
Create simple php project with src directory and put php file with next code to this directory

<?php

namespace MyNameSpace;

class HelloWorld
{
    public function foo(int $p1, $p2)
    {
    }
}

Add next composer.json to the root of project

{
  "require": {
    "phpstan/phpstan": "@stable"
  }
}

Perform composer install
Try to run PhpStan using php interpreter from docker container with CLI command like

docker run -v <Local Path To Project>:/opt/project php:7.4 /opt/project/vendor/bin/phpstan analyse /opt/project/src --error-format=checkstyle --level=7

Result will be like next

 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle>
<file name="pt/project/src/HelloWorld.php">
  <error line="7" column="1" severity="error" message="Method MyNameSpace\HelloWorld::foo() has no return typehint specified." />
  <error line="7" column="1" severity="error" message="Method MyNameSpace\HelloWorld::foo() has parameter $p2 with no typehint specified." />
</file>
</checkstyle>

As you can see <file name="pt/project/src/HelloWorld.php"> has cut path and should be <file name="/opt/project/src/HelloWorld.php">

The same command but with other error formatter (for example prettyJson) prints correct path to the output

1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

{
    "totals": {
        "errors": 0,
        "file_errors": 2
    },
    "files": {
        "/opt/project/src/HelloWorld.php": {
            "errors": 2,
            "messages": [
                {
                    "message": "Method MyNameSpace\\HelloWorld::foo() has no return typehint specified.",
                    "line": 7,
                    "ignorable": true
                },
                {
                    "message": "Method MyNameSpace\\HelloWorld::foo() has parameter $p2 with no typehint specified.",
                    "line": 7,
                    "ignorable": true
                }
            ]
        }
    },
    "errors": []

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions