Skip to content

Commit 49e771e

Browse files
committed
Added regression test
1 parent e33a574 commit 49e771e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

Diff for: tests/PHPStan/Rules/Properties/MissingReadOnlyPropertyAssignRuleTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
class 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) {

Diff for: tests/PHPStan/Rules/Properties/data/bug-10048.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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();

0 commit comments

Comments
 (0)