Skip to content

Commit 5d3ff04

Browse files
committed
add FilesystemHelper
1 parent 1599183 commit 5d3ff04

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=8.1",
8-
"phpstan/phpstan": "^1.10",
9-
"symfony/filesystem": "^6.2"
8+
"phpstan/phpstan": "^1.10"
109
},
1110
"require-dev": {
1211
"php-parallel-lint/php-parallel-lint": "^1.3",

src/ErrorFormatter/SymplifyErrorFormatter.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
use PHPStan\Command\ErrorFormatter\ErrorFormatter;
1111
use PHPStan\Command\Output;
1212
use PHPStan\Command\OutputStyle;
13-
use Symfony\Component\Filesystem\Filesystem;
1413
use Symplify\PHPStanExtensions\Console\Terminal;
1514
use Symplify\PHPStanExtensions\Enum\ResultStatus;
15+
use Symplify\PHPStanExtensions\FilesystemHelper;
1616

1717
/**
1818
* @see \Symplify\PHPStanExtensions\Tests\ErrorFormatter\SymplifyErrorFormatterTest
@@ -92,10 +92,7 @@ private function getRelativePath(string $filePath): string
9292
return $clearFilePath;
9393
}
9494

95-
$filesystem = new Filesystem();
96-
$relativeFilePath = $filesystem->makePathRelative($clearFilePath, getcwd());
97-
98-
return rtrim($relativeFilePath, '/');
95+
return FilesystemHelper::resolveFromCwd($clearFilePath);
9996
}
10097

10198
private function regexMessage(string $message): string

src/FilesystemHelper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanExtensions;
6+
7+
final class FilesystemHelper
8+
{
9+
public static function resolveFromCwd(string $filePath): string
10+
{
11+
// make path relative with native PHP
12+
$realPath = (string) realpath($filePath);
13+
$relativeFilePath = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $realPath);
14+
15+
return rtrim($relativeFilePath, '/');
16+
}
17+
}

0 commit comments

Comments
 (0)