Skip to content

Commit 3e83d66

Browse files
committed
Create static_variable_in_method.php.inc
Test RemoveNonExistingVarAnnotationRector with static variable in method
1 parent 33bb8a6 commit 3e83d66

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector\Fixture;
4+
5+
final class DemoFile
6+
{
7+
public function run(int $param): int
8+
{
9+
/**
10+
* Rector should not remove this @var annotation.
11+
*
12+
* @var array<int,int>
13+
*/
14+
static $cached_result = [];
15+
16+
if (!isset($cached_result[$param])) {
17+
$cached_result[$param] = doExpensiveCalculation($param);
18+
}
19+
20+
return $cached_result[$param];
21+
}
22+
}
23+
-----
24+
<?php
25+
26+
namespace Rector\Tests\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector\Fixture;
27+
28+
final class DemoFile
29+
{
30+
public function run(int $param): int
31+
{
32+
/**
33+
* Rector should not remove this @var annotation.
34+
*/
35+
static $cached_result = [];
36+
37+
if (!isset($cached_result[$param])) {
38+
$cached_result[$param] = doExpensiveCalculation($param);
39+
}
40+
41+
return $cached_result[$param];
42+
}
43+
}

0 commit comments

Comments
 (0)