Skip to content

Commit fcc2ca4

Browse files
committed
fix - invalid visibility - another way to solve commit 1163b31 with better results - kokororin/vscode-phpfmt#172
1 parent 35fbab8 commit fcc2ca4

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

fmt.stub.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6589,21 +6589,8 @@ public function format($source) {
65896589
}
65906590
break;
65916591
case '?':
6592-
$peek = null;
6593-
$i = $this->ptr + 1;
6594-
$futile_tokens = array_merge($this->ignoreFutileTokens, [T_STRING, T_ARRAY, T_NAME_RELATIVE, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED]);
6595-
while (1) {
6596-
if (count($this->tkns) <= ++$i) {
6597-
break;
6598-
}
6599-
$mpeek = $this->tkns[$i];
6600-
if (isset($mpeek[0]) && ! in_array($mpeek[0], $futile_tokens)) {
6601-
$peek = $mpeek[0];
6602-
break;
6603-
}
6604-
}
6605-
if ($this->rightTokenIs([T_STRING, T_ARRAY, T_NAME_RELATIVE, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED]) && $peek === T_VARIABLE) {
6606-
$type = '?';
6592+
if ($this->rightUsefulTokenIs([T_STRING, T_ARRAY, T_NAME_RELATIVE, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED])) {
6593+
$this->tkns[$this->ptr + 1][1] = $text . $this->tkns[$this->ptr + 1][1];
66076594
} else {
66086595
$this->appendCode($text);
66096596
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
//passes:PSR2ModifierVisibilityStaticOrder
3+
//version:8
4+
function foo(?string $bar): void {
5+
}
6+
class Foo {
7+
static public function bar(?string $baz) {
8+
}
9+
}
10+
11+
function faa(?string $bar): void {
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
//passes:PSR2ModifierVisibilityStaticOrder
3+
//version:8
4+
function foo(?string $bar): void {
5+
}
6+
class Foo {
7+
public static function bar(?string $baz) {
8+
}
9+
}
10+
11+
function faa(?string $bar): void {
12+
}

0 commit comments

Comments
 (0)