Skip to content

Commit 1b7edb3

Browse files
committed
Added regression test
1 parent f677acc commit 1b7edb3

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/PHPStan/Rules/Properties/TypesAssignedToPropertiesRuleTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,10 @@ public function testPropertyHooks(): void
779779
]);
780780
}
781781

782+
public function testBug11171(): void
783+
{
784+
$this->checkExplicitMixed = true;
785+
$this->analyse([__DIR__ . '/data/bug-11171.php'], []);
786+
}
787+
782788
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Bug11171;
4+
5+
class TypeExpression
6+
{
7+
public string $value;
8+
9+
/**
10+
* @var list<array{start_index: int, expression: self}>
11+
*/
12+
public array $innerTypeExpressions = [];
13+
14+
/**
15+
* @param \Closure(self): void $callback
16+
*/
17+
public function walkTypes(\Closure $callback): void
18+
{
19+
$startIndexOffset = 0;
20+
21+
foreach ($this->innerTypeExpressions as $k => ['start_index' => $startIndexOrig,
22+
'expression' => $inner,]) {
23+
$this->innerTypeExpressions[$k]['start_index'] += $startIndexOffset;
24+
25+
$innerLengthOrig = \strlen($inner->value);
26+
27+
$inner->walkTypes($callback);
28+
29+
$this->value = substr_replace(
30+
$this->value,
31+
$inner->value,
32+
$startIndexOrig + $startIndexOffset,
33+
$innerLengthOrig
34+
);
35+
36+
$startIndexOffset += \strlen($inner->value) - $innerLengthOrig;
37+
}
38+
39+
$callback($this);
40+
}
41+
}

0 commit comments

Comments
 (0)