diff --git a/src/Formatter.php b/src/Formatter.php index afd1343..1156876 100644 --- a/src/Formatter.php +++ b/src/Formatter.php @@ -46,12 +46,12 @@ class Formatter do { $default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml'; if (is_file($default) === true) { - return array($default); + return [$default]; } $default = $currentDir . DIRECTORY_SEPARATOR . 'phpcs.xml.dist'; if (is_file($default) === true) { - return array($default); + return [$default]; } $lastDir = $currentDir; diff --git a/src/Protocol/TextEdit.php b/src/Protocol/TextEdit.php index 235737f..8ca1d43 100644 --- a/src/Protocol/TextEdit.php +++ b/src/Protocol/TextEdit.php @@ -23,7 +23,7 @@ class TextEdit */ public $newText; - public function __construct(Range $range = null, string $newText) + public function __construct(Range $range = null, string $newText = null) { $this->range = $range; $this->newText = $newText; diff --git a/src/utils.php b/src/utils.php index 848c286..eb0ab7a 100644 --- a/src/utils.php +++ b/src/utils.php @@ -41,10 +41,6 @@ function pathToUri(string $filepath): string { */ function uriToPath(string $uri) { - $position = strpos($uri, '://'); - if (! $position) { - return $uri; - } - $path = substr($uri, $position + 3); - return strpos($path, ':') ? str_replace('/', "\\", substr($path, 1)) : $path; + $path = urldecode(parse_url($uri)['path']); + return strpos($path, ':') ? str_replace(\DIRECTORY_SEPARATOR, '\\', substr($path, 1)) : $path; } diff --git a/tests/FormatterTest.php b/tests/FormatterTest.php index 7ce7d04..c6af09a 100644 --- a/tests/FormatterTest.php +++ b/tests/FormatterTest.php @@ -16,7 +16,7 @@ class FormatterTest extends TestCase $input = file_get_contents(__DIR__ . '/../fixtures/format.php'); $output = file_get_contents(__DIR__ . '/../fixtures/format_expected.php'); - $edits = $formatter->format($input, "whatever"); + $edits = $formatter->format($input, 'whatever'); $this->assertTrue($edits[0]->newText === $output); } @@ -25,7 +25,7 @@ class FormatterTest extends TestCase $formatter = new Formatter(); $expected = file_get_contents(__DIR__ . '/../fixtures/format_expected.php'); - $edits = $formatter->format($expected, "whatever"); + $edits = $formatter->format($expected, 'whatever'); $this->assertTrue($edits == []); } diff --git a/tests/Utils/FileUriTest.php b/tests/Utils/FileUriTest.php index 4d45ede..1846637 100644 --- a/tests/Utils/FileUriTest.php +++ b/tests/Utils/FileUriTest.php @@ -34,24 +34,24 @@ class FileUriTest extends TestCase $this->assertEquals('file:///c%3A/foo/bar.baz', $uri); } - public function testUriToPathUnix() + public function testUriToPath() { - $uri = "file:///home/foo/bar/Test.php"; - $this->assertEquals("/home/foo/bar/Test.php", \LanguageServer\uriToPath($uri)); + $uri = 'file:///var/log'; + $this->assertEquals('/var/log', \LanguageServer\uriToPath($uri)); - $uri = "/home/foo/bar/Test.php"; - $this->assertEquals("/home/foo/bar/Test.php", \LanguageServer\uriToPath($uri)); + $uri = 'file:///usr/local/bin'; + $this->assertEquals('/usr/local/bin', \LanguageServer\uriToPath($uri)); - $uri = "/home/foo space/bar/Test.php"; - $this->assertEquals("/home/foo space/bar/Test.php", \LanguageServer\uriToPath($uri)); - } - - public function testUriToPathWindows() - { - $uri = "file:///c:/home/foo/bar/Test.php"; - $this->assertEquals("c:\\home\\foo\\bar\\Test.php", \LanguageServer\uriToPath($uri)); - - $uri = "c:\\home\\foo\\bar\\Test.php"; - $this->assertEquals("c:\\home\\foo\\bar\\Test.php", \LanguageServer\uriToPath($uri)); + $uri = 'file:///d/e/f'; + $this->assertEquals('/d/e/f', \LanguageServer\uriToPath($uri)); + + $uri = 'file:///a/b/c/test.txt'; + $this->assertEquals('/a/b/c/test.txt', \LanguageServer\uriToPath($uri)); + + $uri = 'file:///c%3A/foo/bar.baz'; + $this->assertEquals('c:\\foo\\bar.baz', \LanguageServer\uriToPath($uri)); + + $uri = 'file:///c%3A/path/to/file/d%C3%BCr%C3%BCm+d%C3%B6ner.php'; + $this->assertEquals('c:\\path\\to\\file\\dürüm döner.php', \LanguageServer\uriToPath($uri)); } }