-
Notifications
You must be signed in to change notification settings - Fork 653
/
UnsupportedPropertyReferenceUsage.php
93 lines (87 loc) · 2.82 KB
/
UnsupportedPropertyReferenceUsage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
declare(strict_types=1);
namespace Psalm\Tests;
use Psalm\Tests\Traits\InvalidCodeAnalysisTestTrait;
use Psalm\Tests\Traits\ValidCodeAnalysisTestTrait;
class UnsupportedPropertyReferenceUsage extends TestCase
{
use ValidCodeAnalysisTestTrait;
use InvalidCodeAnalysisTestTrait;
public function providerValidCodeParse(): iterable
{
return [
'can be suppressed' => [
'code' => <<<'PHP'
<?php
class A {
public int $b = 0;
}
$a = new A();
/** @psalm-suppress UnsupportedPropertyReferenceUsage */
$b = &$a->b;
PHP,
],
];
}
public function providerInvalidCodeParse(): iterable
{
return [
'instance property' => [
'code' => <<<'PHP'
<?php
class A {
public int $b = 0;
}
$a = new A();
$b = &$a->b;
$b = ''; // Fatal error
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
],
'static property' => [
'code' => <<<'PHP'
<?php
class A {
public static int $b = 0;
}
$b = &A::$b;
$b = ''; // Fatal error
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
],
'readonly property' => [
'code' => <<<'PHP'
<?php
class A {
public function __construct(
public readonly int $b,
) {
}
}
$a = new A(0);
$b = &$a->b;
$b = 1; // Fatal error
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
'error_levels' => [],
'php_version' => '8.1',
],
'instance property, foreach assignment' => [
'code' => <<<'PHP'
<?php
class A {
public readonly array $b = [1, 2, 3];
}
$a = new A();
$b = &$a->b;
foreach ($a->b as &$b) {
$b = 4; // Fatal error
}
PHP,
'error_message' => 'UnsupportedPropertyReferenceUsage',
'error_levels' => [],
'php_version' => '8.1',
],
];
}
}