1
0
Fork 0

Use PHP_CodeSniffer as a formatter

pull/35/head
Michal Niewrzal 2016-10-04 11:53:50 +02:00 committed by Felix Becker
parent 552d645cc4
commit 8de18847ee
5 changed files with 23 additions and 27 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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 == []);
}

View File

@ -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));
}
}