File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
tests/PHPStan/Rules/Properties Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1616class MissingReadOnlyPropertyAssignRuleTest extends RuleTestCase
1717{
1818
19+ private bool $ shouldNarrowMethodScopeFromConstructor = false ;
20+
1921 protected function getRule (): Rule
2022 {
2123 return new MissingReadOnlyPropertyAssignRule (
@@ -31,6 +33,11 @@ protected function getRule(): Rule
3133 );
3234 }
3335
36+ public function shouldNarrowMethodScopeFromConstructor (): bool
37+ {
38+ return $ this ->shouldNarrowMethodScopeFromConstructor ;
39+ }
40+
3441 protected function getReadWritePropertiesExtensions (): array
3542 {
3643 return [
@@ -375,6 +382,16 @@ public function testBug9863(): void
375382 ]);
376383 }
377384
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+
378395 public function testBug9864 (): void
379396 {
380397 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