Skip to content

Commit

Permalink
fix - missing static when using readonly - #90
Browse files Browse the repository at this point in the history
  • Loading branch information
driade committed Jan 8, 2025
1 parent 8493749 commit 9c30a5f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions fmt.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6466,6 +6466,7 @@ public function format($source) {
$visibility = null;
$finalOrAbstract = null;
$static = null;
$readonly = null;
$type = null;
$skipWhitespaces = false;
$touchedClassInterfaceTrait = false;
Expand Down Expand Up @@ -6525,6 +6526,11 @@ public function format($source) {
$this->appendCode($static. ' ');
$static = null;
$skipWhitespaces = false;
}
if ($readonly !== null) {
$this->appendCode($readonly. ' ');
$readonly = null;
$skipWhitespaces = false;
}
$this->appendCode($text);
$this->printUntilAny([T_EXTENDS, T_IMPLEMENTS, ST_CURLY_OPEN]);
Expand Down Expand Up @@ -6651,6 +6657,23 @@ public function format($source) {
$this->appendCode($text);
break;
case T_READONLY:
if (! $this->leftTokenIs(T_DOUBLE_COLON)) {
if (!is_null($visibility)) {
$readonly = $text;
$skipWhitespaces = true;
break;
} elseif ($this->leftTokenIs([T_FINAL])) { // ??
$readonly = $text;
$visibility = 'public';
break;
} elseif (!$this->rightTokenIs([T_VARIABLE, T_DOUBLE_COLON]) && !$this->leftTokenIs([T_NEW, ST_COMMA])) {
$readonly = $text;
$skipWhitespaces = true;
break;
}
}
$this->appendCode($text);
break;
case T_STATIC:
if (! $this->leftTokenIs(T_DOUBLE_COLON)) {
if (!is_null($visibility)) {
Expand Down Expand Up @@ -6679,9 +6702,11 @@ public function format($source) {
null !== $finalOrAbstract && $this->appendCode($finalOrAbstract . $this->getSpace());
null !== $visibility && $this->appendCode($visibility . $this->getSpace());
null !== $static && $this->appendCode($static . $this->getSpace());
null !== $readonly && $this->appendCode($readonly . $this->getSpace());
null !== $type && $this->appendCode($type . $this->getSpace());
$finalOrAbstract = null;
$visibility = null;
$readonly = null;
$static = null;
$type = null;
$skipWhitespaces = false;
Expand Down Expand Up @@ -6733,6 +6758,7 @@ public function format($source) {
$this->appendCode($text);
$visibility = null;
$static = null;
$readonly = null;
$skipWhitespaces = false;
if ($finalOrAbstract !== null && 'abstract' == strtolower($finalOrAbstract)) {
$finalOrAbstract = null;
Expand Down
13 changes: 13 additions & 0 deletions tests/Original/494-missing-static.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
//passes:PSR2ModifierVisibilityStaticOrder
//version:8.1
class a {
public static string $endpoint = '';
static string $endpoint0 = '';
private static string $endpoint1 = '';
private readonly string $endpoint3 = '';
private static readonly string $endpoint4 = '';
public static readonly string $endpoint5 = '';
static readonly string $endpoint6 = '';
final readonly string $endpoint7 = '';
}
13 changes: 13 additions & 0 deletions tests/Original/494-missing-static.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
//passes:PSR2ModifierVisibilityStaticOrder
//version:8.1
class a {
public static string $endpoint = '';
static string $endpoint0 = '';
private static string $endpoint1 = '';
private readonly string $endpoint3 = '';
private static readonly string $endpoint4 = '';
public static readonly string $endpoint5 = '';
static readonly string $endpoint6 = '';
final public readonly string $endpoint7 = '';
}

0 comments on commit 9c30a5f

Please sign in to comment.