forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadonly-property-assign-clone-with.php
More file actions
50 lines (38 loc) · 1006 Bytes
/
readonly-property-assign-clone-with.php
File metadata and controls
50 lines (38 loc) · 1006 Bytes
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
<?php // lint >= 8.5
namespace ReadonlyPropertyAssignCloneWith;
class Foo
{
private readonly int $priv;
protected readonly int $prot;
public readonly int $pub;
public public(set) readonly int $pubSet;
public function doFoo(): void
{
clone ($this, [
'priv' => 1,
'prot' => 1,
'pub' => 1,
]);
}
}
function (Foo $foo): void {
clone ($foo, [
'priv' => 1, // reported in AccessPropertiesInAssignRule
'prot' => 1, // reported in AccessPropertiesInAssignRule
'pub' => 1, // reported in AccessPropertiesInAssignRule
'pubSet' => 1, // reported here - readonly property assigned outside declaring class
]);
};
final readonly class Bar
{
public function __construct(public string $value) {}
public function withValue(string $value): self
{
return clone($this, ['value' => $value]); // OK - inside declaring class
}
}
function (Bar $bar): void {
clone ($bar, [
'value' => 'newVal', // reported in AccessPropertiesInAssignRule (protected(set)) - and also here
]);
};