Skip to content

Commit 8bb2e30

Browse files
committed
fix - PSR visibility reordering for intersection and DNF property types - kokororin/vscode-phpfmt#199
1 parent 7e00e73 commit 8bb2e30

7 files changed

Lines changed: 116 additions & 2 deletions

fmt.stub.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7102,8 +7102,17 @@ public function format($source)
71027102
break;
71037103
case ST_PARENTHESES_OPEN:
71047104
case ST_PARENTHESES_CLOSE:
7105-
$this->appendCode($text);
7106-
$touchedClassInterfaceTrait = false;
7105+
if (
7106+
null !== $visibility ||
7107+
null !== $finalOrAbstract ||
7108+
null !== $static ||
7109+
null !== $type
7110+
) {
7111+
$type .= $text;
7112+
} else {
7113+
$this->appendCode($text);
7114+
$touchedClassInterfaceTrait = false;
7115+
}
71077116
break;
71087117
case T_WHITESPACE:
71097118
if (! $skipWhitespaces) {
@@ -7124,6 +7133,7 @@ public function format($source)
71247133
$this->appendCode($text);
71257134
break;
71267135
case '|':
7136+
case T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG:
71277137
case T_NAME_RELATIVE:
71287138
case T_NAME_QUALIFIED:
71297139
case T_NAME_FULLY_QUALIFIED:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
//version:8.1.0
3+
4+
class A
5+
{
6+
7+
}
8+
class B
9+
{
10+
11+
}
12+
class C
13+
{
14+
public A&B $test;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
//version:8.1.0
3+
4+
class A
5+
{
6+
7+
}
8+
class B
9+
{
10+
11+
}
12+
class C
13+
{
14+
public A&B $test;
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
//version:8.1.0
3+
4+
class A
5+
{}
6+
interface B
7+
{}
8+
9+
class Example
10+
{
11+
public A&B $plain;
12+
private readonly A&B $readonlyProp;
13+
protected static A&B $shared;
14+
15+
public function __construct(public A&B $promoted, private readonly A&B $promotedReadonly)
16+
{
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
//version:8.1.0
3+
4+
class A
5+
{}
6+
interface B
7+
{}
8+
9+
class Example
10+
{
11+
public A&B $plain;
12+
private readonly A&B $readonlyProp;
13+
protected static A&B $shared;
14+
15+
public function __construct(public A&B $promoted, private readonly A&B $promotedReadonly)
16+
{
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
//version:8.2.0
3+
4+
class A
5+
{}
6+
interface B
7+
{}
8+
interface C
9+
{}
10+
11+
class Example
12+
{
13+
public (A&B)|C $choice;
14+
private C|(A&B) $choice2;
15+
16+
public function __construct(public (A&B)|C $promoted)
17+
{
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
//version:8.2.0
3+
4+
class A
5+
{}
6+
interface B
7+
{}
8+
interface C
9+
{}
10+
11+
class Example
12+
{
13+
public (A&B)|C $choice;
14+
private C|(A&B) $choice2;
15+
16+
public function __construct(public (A&B) | C $promoted)
17+
{
18+
}
19+
}

0 commit comments

Comments
 (0)