diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index e6f05540b55..bebf471599c 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -244,7 +244,7 @@ class Config protected $extra_files; /** - * The base directory of this config file + * The base directory of this config file without trailing slash * * @var string */ @@ -1445,7 +1445,7 @@ private static function fromXmlAndPaths( if (!$file_path) { throw new ConfigException( 'Cannot resolve stubfile path ' - . rtrim($config->base_dir, DIRECTORY_SEPARATOR) + . $config->base_dir . DIRECTORY_SEPARATOR . $stub_file['name'], ); @@ -1582,11 +1582,11 @@ public function safeSetCustomErrorLevel(string $issue_key, string $error_level): private function loadFileExtensions(SimpleXMLElement $extensions): void { foreach ($extensions as $extension) { - $extension_name = preg_replace('/^\.?/', '', (string)$extension['name'], 1); + $extension_name = preg_replace('/^\.?/', '', (string) $extension['name'], 1); $this->file_extensions[] = $extension_name; if (isset($extension['scanner'])) { - $path = $this->base_dir . (string)$extension['scanner']; + $path = $this->base_dir . DIRECTORY_SEPARATOR . (string) $extension['scanner']; if (!file_exists($path)) { throw new ConfigException('Error parsing config: cannot find file ' . $path); @@ -1596,7 +1596,7 @@ private function loadFileExtensions(SimpleXMLElement $extensions): void } if (isset($extension['checker'])) { - $path = $this->base_dir . (string)$extension['checker']; + $path = $this->base_dir . DIRECTORY_SEPARATOR . (string) $extension['checker']; if (!file_exists($path)) { throw new ConfigException('Error parsing config: cannot find file ' . $path); @@ -1817,7 +1817,7 @@ private function getPluginClassForPath(Codebase $codebase, string $path, string public function shortenFileName(string $to): string { if (!is_file($to)) { - return preg_replace('/^' . preg_quote($this->base_dir, '/') . '/', '', $to, 1); + return preg_replace('/^' . preg_quote($this->base_dir . DIRECTORY_SEPARATOR, '/') . '?/', '', $to, 1); } $from = $this->base_dir; diff --git a/tests/Cache/CacheTest.php b/tests/Cache/CacheTest.php index e714256837a..c696aef96dd 100644 --- a/tests/Cache/CacheTest.php +++ b/tests/Cache/CacheTest.php @@ -92,7 +92,7 @@ public function testCacheInteractions( foreach ($interactions as $interaction) { foreach ($interaction['files'] as $file_path => $file_contents) { - $file_path = $config->base_dir . str_replace('/', DIRECTORY_SEPARATOR, $file_path); + $file_path = $config->base_dir . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $file_path); if ($file_contents === null) { $file_provider->deleteFile($file_path); } else { @@ -126,7 +126,7 @@ public static function provideCacheInteractions(): iterable [ [ 'files' => [ - '/src/A.php' => <<<'PHP' + 'src/A.php' => <<<'PHP' <<<'PHP' + 'src/B.php' => <<<'PHP' [ - '/src/B.php' => null, + 'src/B.php' => null, ], 'issues' => [ - '/src/A.php' => [ + 'src/A.php' => [ 'UndefinedClass: Class, interface or enum named B does not exist', ], ], @@ -163,7 +163,7 @@ public function do(): void [ [ 'files' => [ - '/src/A.php' => <<<'PHP' + 'src/A.php' => <<<'PHP' <<<'PHP' + 'src/B.php' => <<<'PHP' [ - '/src/A.php' => [ + 'src/A.php' => [ "NullableReturnStatement: The declared return type 'int' for A::foo is not nullable, but the function returns 'int|null'", "InvalidNullableReturnType: The declared return type 'int' for A::foo is not nullable, but 'int|null' contains null", ], @@ -188,7 +188,7 @@ class B { ], [ 'files' => [ - '/src/B.php' => <<<'PHP' + 'src/B.php' => <<<'PHP' [ - '/src/A.php' => <<<'PHP' + 'src/A.php' => <<<'PHP' <<<'PHP' + 'src/B.php' => <<<'PHP' [ - '/src/A.php' => <<<'PHP' + 'src/A.php' => <<<'PHP' [ - '/src/A.php' => [ + 'src/A.php' => [ "UndefinedDocblockClass: Docblock-defined class, interface or enum named T does not exist", ], - '/src/B.php' => [ + 'src/B.php' => [ "InvalidArgument: Argument 1 of A::foo expects T, but 1 provided", ], ], @@ -266,7 +266,7 @@ public function foo($baz): void [ [ 'files' => [ - '/src/A.php' => <<<'PHP' + 'src/A.php' => <<<'PHP' [ - '/src/A.php' => <<<'PHP' + 'src/A.php' => <<<'PHP' [ - '/src/A.php' => [ + 'src/A.php' => [ "UndefinedThisPropertyFetch: Instance property A::\$foo is not defined", "MixedReturnStatement: Could not infer a return type", "MixedInferredReturnType: Could not verify return type 'string' for A::bar", diff --git a/tests/StubTest.php b/tests/StubTest.php index f12fb943ed8..94bcdf73cfb 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -864,7 +864,7 @@ function_exists("fooBar"); public function testNoStubFunction(): void { - $this->expectExceptionMessage('UndefinedFunction - /src/somefile.php:2:22 - Function barBar does not exist'); + $this->expectExceptionMessage('UndefinedFunction - src/somefile.php:2:22 - Function barBar does not exist'); $this->expectException(CodeException::class); $this->project_analyzer = $this->getProjectAnalyzerWithConfig( TestConfig::loadFromXML( diff --git a/tests/TestConfig.php b/tests/TestConfig.php index dc72087410f..1b8a1ea5c94 100644 --- a/tests/TestConfig.php +++ b/tests/TestConfig.php @@ -9,8 +9,6 @@ use function getcwd; -use const DIRECTORY_SEPARATOR; - class TestConfig extends Config { private static ?ProjectFileFilter $cached_project_files = null; @@ -28,7 +26,7 @@ public function __construct() $this->level = 1; $this->cache_directory = null; - $this->base_dir = getcwd() . DIRECTORY_SEPARATOR; + $this->base_dir = getcwd(); if (!self::$cached_project_files) { self::$cached_project_files = ProjectFileFilter::loadFromXMLElement(