diff --git a/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php b/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php index fa5c42274b..59b6c6f987 100644 --- a/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php +++ b/tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php @@ -241,4 +241,26 @@ public function testBug5337(): void $this->analyse([__DIR__ . '/data/bug-5337.php'], []); } + public function testBug5971(): void + { + if (PHP_VERSION_ID < 70400) { + $this->markTestSkipped('Test requires PHP 7.4.'); + } + + $this->alwaysWrittenTags = []; + $this->alwaysReadTags = []; + $this->analyse([__DIR__ . '/data/bug-5971.php'], []); + } + + public function testBug6107(): void + { + if (PHP_VERSION_ID < 70400) { + $this->markTestSkipped('Test requires PHP 7.4.'); + } + + $this->alwaysWrittenTags = []; + $this->alwaysReadTags = []; + $this->analyse([__DIR__ . '/data/bug-6107.php'], []); + } + } diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-5971.php b/tests/PHPStan/Rules/DeadCode/data/bug-5971.php new file mode 100644 index 0000000000..c88ee5caf5 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-5971.php @@ -0,0 +1,33 @@ += 7.4 + +namespace Bug5971; + +class TestEmpty +{ + private ?array $test; + + public function write(): void + { + $this->test = []; + } + + public function read(): bool + { + return empty($this->test); + } +} + +class TestIsset +{ + private ?string $test; + + public function write(string $string): void + { + $this->test = $string; + } + + public function read(): bool + { + return isset($this->test); + } +} diff --git a/tests/PHPStan/Rules/DeadCode/data/bug-6107.php b/tests/PHPStan/Rules/DeadCode/data/bug-6107.php new file mode 100644 index 0000000000..65452f5179 --- /dev/null +++ b/tests/PHPStan/Rules/DeadCode/data/bug-6107.php @@ -0,0 +1,18 @@ += 7.4 + +namespace Bug6107; + +class Test +{ + private ?\stdClass $item; + + public function __construct(?\stdClass $item) + { + $this->item = $item; + } + + public function handle(): void + { + $value = $this->item->value ?? 'custom value'; + } +}