File tree 2 files changed +43
-0
lines changed
tests/PHPStan/Rules/Properties
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 16
16
class MissingReadOnlyPropertyAssignRuleTest extends RuleTestCase
17
17
{
18
18
19
+ private bool $ shouldNarrowMethodScopeFromConstructor = false ;
20
+
19
21
protected function getRule (): Rule
20
22
{
21
23
return new MissingReadOnlyPropertyAssignRule (
@@ -31,6 +33,11 @@ protected function getRule(): Rule
31
33
);
32
34
}
33
35
36
+ public function shouldNarrowMethodScopeFromConstructor (): bool
37
+ {
38
+ return $ this ->shouldNarrowMethodScopeFromConstructor ;
39
+ }
40
+
34
41
protected function getReadWritePropertiesExtensions (): array
35
42
{
36
43
return [
@@ -375,6 +382,16 @@ public function testBug9863(): void
375
382
]);
376
383
}
377
384
385
+ public function testBug10048 (): void
386
+ {
387
+ if (PHP_VERSION_ID < 80100 ) {
388
+ $ this ->markTestSkipped ('Test requires PHP 8.1. ' );
389
+ }
390
+
391
+ $ this ->shouldNarrowMethodScopeFromConstructor = true ;
392
+ $ this ->analyse ([__DIR__ . '/data/bug-10048.php ' ], []);
393
+ }
394
+
378
395
public function testBug9864 (): void
379
396
{
380
397
if (PHP_VERSION_ID < 80100 ) {
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace Bug10048 ;
4
+
5
+ class Foo {
6
+ private readonly string $ bar ;
7
+ private readonly \Closure $ callback ;
8
+ public function __construct () {
9
+ $ this ->bar = "hi " ;
10
+ $ this ->useBar ();
11
+ echo $ this ->bar ;
12
+ $ this ->callback = function () {
13
+ $ this ->useBar ();
14
+ };
15
+ }
16
+
17
+ private function useBar (): void {
18
+ echo $ this ->bar ;
19
+ }
20
+
21
+ public function useCallback (): void {
22
+ call_user_func ($ this ->callback );
23
+ }
24
+ }
25
+
26
+ (new Foo ())->useCallback ();
You can’t perform that action at this time.
0 commit comments