Repository: PHP-CS-Fixer/PHP-CS-Fixer (PHP)

Issue:
Disabling the cache breaks the GitLab reporter
## Bug report

### Description

When run with `--using-cache=no` the resulting GitLab report is broken because then the paths are prefixed with the project name, which means GitLab can't find/map them anymore.

### Runtime version

PHP CS Fixer 3.14.4 (1b3d9db) Oliva by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.0.28

### Used command

`php-cs-fixer fix --no-interaction --dry-run --format=gitlab --using-cache=no > php-cs-fixer.json`

### Configuration file

```php
<?php

return (new PhpCsFixer\Config)
    ->setFinder((new PhpCsFixer\Finder)
        ->in([
            __DIR__ . '/src',
            __DIR__ . '/tests',
        ])
        ->notPath(['DependencyInjection/Configuration.php', 'app/var'])
    )
    ->setRiskyAllowed(true)
    ->setRules([
        '@Symfony' => true,

        // declare strict types must be on first line after opening tag
        'blank_line_after_opening_tag' => false, // overwrite @Symfony
        'linebreak_after_opening_tag' => false, // overwrite @Symfony
        'declare_strict_types' => true, // custom

        // we want spaces
        'concat_space' => ['spacing' => 'one'],
        // but not on type casts
        'cast_spaces' => ['space' => 'none'],

        // allow throw's in multiple lines, so message can be a long string
        'single_line_throw' => false, // overwrite @Symfony

        // we do not want our argument lists aligned like a table
        'phpdoc_align' => ['align' => 'left'],

        // because some people have their own style of naming test methods
        'php_unit_method_casing' => false,
    ]);
```

### Output with `--using-cache=no`

```json
[
  {
    "description": "braces",
    "fingerprint": "b92e9637b0fe530ddad1dfbb9ca1a76e",
    "severity": "minor",
    "location": {
      "path": "elastic-bundle/src/Elastically/IndexesRepository.php",
      "lines": {
        "begin": 0
      }
    }
  }
]
```

### Output without `--using-cache=no`

```json
[
  {
    "description": "braces",
    "fingerprint": "00176622970ec9012453eb1e0d7a25ea",
    "severity": "minor",
    "location": {
      "path": "src/Elastically/IndexesRepository.php",
      "lines": {
        "begin": 0
      }
    }
  }
]
```


Discussion:

Patch:
diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php
index 5494fda165f..58717dd4371 100644
--- a/src/Console/ConfigurationResolver.php
+++ b/src/Console/ConfigurationResolver.php
@@ -309,9 +309,10 @@ public function getDirectory(): DirectoryInterface
                 $absolutePath = $filesystem->isAbsolutePath($path)
                     ? $path
                     : $this->cwd.\DIRECTORY_SEPARATOR.$path;
+                $absolutePath = \dirname($absolutePath);
             }
 
-            $this->directory = new Directory(\dirname($absolutePath));
+            $this->directory = new Directory($absolutePath);
         }
 
         return $this->directory;


Test patch:
diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php
index 98e596d07f1..766ea0509f4 100644
--- a/tests/Console/ConfigurationResolverTest.php
+++ b/tests/Console/ConfigurationResolverTest.php
@@ -1173,7 +1173,7 @@ public static function provideDeprecatedFixerConfiguredCases(): array
     public static function provideGetDirectoryCases(): array
     {
         return [
-            [null, '/my/path/my/file', 'path/my/file'],
+            [null, '/my/path/my/file', 'my/file'],
             ['/my/path/.php-cs-fixer.cache', '/my/path/my/file', 'my/file'],
             ['/my/path2/dir/.php-cs-fixer.cache', '/my/path2/dir/dir2/file', 'dir2/file'],
             ['dir/.php-cs-fixer.cache', '/my/path/dir/dir3/file', 'dir3/file'],
diff --git a/tests/Smoke/PharTest.php b/tests/Smoke/PharTest.php
index 624579ddfb8..2c16c0c4a7a 100644
--- a/tests/Smoke/PharTest.php
+++ b/tests/Smoke/PharTest.php
@@ -103,6 +103,8 @@ public function testFixHelp(): void
 
     public static function provideReportCases(): iterable
     {
+        yield ['no'];
+
         yield ['yes'];
     }
 
diff --git a/tests/Smoke/StdinTest.php b/tests/Smoke/StdinTest.php
index 6e827f2e5c4..b2087ebddc5 100644
--- a/tests/Smoke/StdinTest.php
+++ b/tests/Smoke/StdinTest.php
@@ -59,9 +59,8 @@ public function testFixingStdin(): void
         $fileResult = str_replace("\n--- ".$path."\n", "\n--- php://stdin\n", $fileResult);
         $fileResult = str_replace("\n+++ ".$path."\n", "\n+++ php://stdin\n", $fileResult);
 
-        $path = str_replace('/', \DIRECTORY_SEPARATOR, basename(realpath($cwd)).'/'.$inputFile);
         $fileResult = Preg::replace(
-            '#/?'.preg_quote($path, '#').'#',
+            '#/?'.preg_quote($inputFile, '#').'#',
             'php://stdin',
             $fileResult
         );