Skip to content

Commit 3ce565c

Browse files
committed
Fix
1 parent 56cee8c commit 3ce565c

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

Diff for: src/Analyser/NodeScopeResolver.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -3318,7 +3318,7 @@ private function processAssignVar(
33183318
new GetOffsetValueTypeExpr($assignedExpr, $dimExpr),
33193319
$nodeCallback,
33203320
$context,
3321-
$processExprCallback, // TODO
3321+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, []),
33223322
$enterExpressionAssign,
33233323
);
33243324
$scope = $result->getScope();
@@ -3557,9 +3557,9 @@ private function enterForeach(MutatingScope $scope, Foreach_ $stmt): MutatingSco
35573557
$stmt->valueVar,
35583558
new GetIterableValueTypeExpr($stmt->expr),
35593559
static function (): void {
3560-
}, // todo
3560+
},
35613561
ExpressionContext::createDeep(),
3562-
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, []), // todo
3562+
static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, []),
35633563
true,
35643564
)->getScope();
35653565
$vars = array_merge($vars, $this->getAssignedVariables($stmt->valueVar));

Diff for: tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -2293,4 +2293,17 @@ public function testBug6306(): void
22932293
$this->analyse([__DIR__ . '/data/bug-6306.php'], []);
22942294
}
22952295

2296+
public function testRectorDoWhileVarIssue(): void
2297+
{
2298+
$this->checkThisOnly = false;
2299+
$this->checkNullables = true;
2300+
$this->checkUnionTypes = true;
2301+
$this->analyse([__DIR__ . '/data/rector-do-while-var-issue.php'], [
2302+
[
2303+
'Parameter #1 $cls of method RectorDoWhileVarIssue\Foo::processCharacterClass() expects string, int|string given.',
2304+
24,
2305+
],
2306+
]);
2307+
}
2308+
22962309
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace RectorDoWhileVarIssue;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(string $cls): void
9+
{
10+
do {
11+
if (doBar()) {
12+
/** @var string $cls */
13+
[$cls] = $this->processCharacterClass($cls);
14+
} else {
15+
$cls = 'foo';
16+
}
17+
} while (doFoo());
18+
}
19+
20+
public function doFoo2(string $cls): void
21+
{
22+
do {
23+
if (doBar()) {
24+
[$cls] = $this->processCharacterClass($cls);
25+
} else {
26+
$cls = 'foo';
27+
}
28+
} while (doFoo());
29+
}
30+
31+
/**
32+
* @return int[]|string[]
33+
*/
34+
private function processCharacterClass(string $cls): array
35+
{
36+
return [];
37+
}
38+
39+
}

0 commit comments

Comments
 (0)