diff --git a/src/Parser/SniffParser.php b/src/Parser/SniffParser.php index ddcdca3..afe51e7 100644 --- a/src/Parser/SniffParser.php +++ b/src/Parser/SniffParser.php @@ -4,6 +4,7 @@ namespace App\Parser; use App\Parser\Exception\NotASniffPath; +use App\Util\Functions; use App\Value\Diff; use App\Value\Property; use App\Value\Sniff; @@ -27,7 +28,7 @@ class SniffParser { public function parse(string $phpFilePath, SourceLocator $projectSourceLocator): Sniff { - $phpFilePath = $this->normalizeSlashes($phpFilePath); + $phpFilePath = Functions::normalizeSlashes($phpFilePath); $astLocator = (new BetterReflection())->astLocator(); $reflector = new ClassReflector( new AggregateSourceLocator([ @@ -212,16 +213,4 @@ private function getUrls(ReflectionClass $classInfo, array $xmlUrls): UrlList return new UrlList(array_merge($urls, $xmlUrls)); } - - /** - * Normalizes all slashes in a file path to forward slashes. - * - * @param string $path File path. - * - * @return string The file path with normalized slashes. - */ - private function normalizeSlashes($path) - { - return str_replace('\\', '/', $path); - } } diff --git a/src/Parser/ViolationParser.php b/src/Parser/ViolationParser.php index e9d27f5..4380e99 100644 --- a/src/Parser/ViolationParser.php +++ b/src/Parser/ViolationParser.php @@ -4,6 +4,7 @@ namespace App\Parser; use App\Parser\Exception\NotAViolationPath; +use App\Util\Functions; use App\Value\Diff; use App\Value\Url; use App\Value\UrlList; @@ -27,6 +28,7 @@ public function parse(string $xmlFilePath): Violation private function getErrorCode(string $xmlFilePath): string { + $xmlFilePath = Functions::normalizeSlashes($xmlFilePath); $part = '([^/]*)'; preg_match("`$part/Docs/$part/{$part}Standard/$part\.xml$`", $xmlFilePath, $matches); if ($matches === []) { diff --git a/src/Util/Functions.php b/src/Util/Functions.php new file mode 100644 index 0000000..70161e8 --- /dev/null +++ b/src/Util/Functions.php @@ -0,0 +1,20 @@ + [ + 'path/to/folder/filename.php', + 'path/to/folder/filename.php', + ], + 'windows_slashes' => [ + 'path\to\folder\filename.php', + 'path/to/folder/filename.php', + ], + 'mixed_slashes' => [ + 'path\to/folder\filename.php', + 'path/to/folder/filename.php', + ], + ]; + } +}