Skip to content

Commit e606f0c

Browse files
committed
Test ReturnNullsafeByRefRule with property hooks
1 parent 9bdcdf3 commit e606f0c

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/PHPStan/Rules/Functions/ReturnNullsafeByRefRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PHPStan\Rules\NullsafeCheck;
66
use PHPStan\Rules\Rule;
77
use PHPStan\Testing\RuleTestCase;
8+
use const PHP_VERSION_ID;
89

910
/**
1011
* @extends RuleTestCase<ReturnNullsafeByRefRule>
@@ -35,4 +36,18 @@ public function testRule(): void
3536
]);
3637
}
3738

39+
public function testPropertyHooks(): void
40+
{
41+
if (PHP_VERSION_ID < 80400) {
42+
$this->markTestSkipped('Test requires PHP 8.4.');
43+
}
44+
45+
$this->analyse([__DIR__ . '/data/return-null-safe-by-ref-property-hooks.php'], [
46+
[
47+
'Nullsafe cannot be returned by reference.',
48+
13,
49+
],
50+
]);
51+
}
52+
3853
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php // lint >= 8.4
2+
3+
namespace ReturnNullSafeByRefPropertyHools;
4+
5+
use stdClass;
6+
7+
class Foo
8+
{
9+
public int $i {
10+
&get {
11+
$foo = new stdClass();
12+
13+
return $foo?->foo;
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)