Skip to content

Commit 2709a00

Browse files
LTSCommerceclaude
andcommitted
fix(phpstan): fix CI failures in RequireVariadicForSingleListParamRule
- Remove redundant assert($node instanceof ClassMethod) — PHPStan already knows the type via @implements Rule<ClassMethod>, making the assert always-true - Replace createStub(Scope::class) with createMockForIntersectionOfInterfaces ([NodeCallbackInvoker::class, Scope::class]) — Scope parameter requires NodeCallbackInvoker intersection to satisfy PHPStan's type for processNode() - Remove redundant (string) casts on getMessage() which already returns string - Add PHPStan\Analyser\NodeCallbackInvoker to composerRequireChecker whitelist Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6b3c993 commit 2709a00

3 files changed

Lines changed: 17 additions & 16 deletions

File tree

qaConfig/composerRequireChecker.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"PhpParser\\Node\\Expr\\Ternary",
6060
"PhpParser\\Node\\NullableType",
6161
"PhpParser\\Node\\Param",
62+
"PHPStan\\Analyser\\NodeCallbackInvoker",
6263
"PHPStan\\Analyser\\Scope",
6364
"PHPStan\\Node\\FileNode",
6465
"PHPStan\\Reflection\\ClassReflection",

src/PHPStan/Rules/RequireVariadicForSingleListParamRule.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public function getNodeType(): string
4747
*/
4848
public function processNode(Node $node, Scope $scope): array
4949
{
50-
\assert($node instanceof ClassMethod);
51-
5250
if (1 !== \count($node->params)) {
5351
return [];
5452
}

tests/Small/PHPStan/Rules/RequireVariadicForSingleListParamRuleTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use PhpParser\Node\Identifier;
1111
use PhpParser\Node\Param;
1212
use PhpParser\Node\Stmt\ClassMethod;
13+
use PHPStan\Analyser\NodeCallbackInvoker;
14+
use PHPStan\Analyser\Scope;
1315
use PHPUnit\Framework\TestCase;
1416

1517
/**
@@ -39,7 +41,7 @@ public function testSingleArrayParamWithListDocblockIsFlagged(): void
3941
'/** @param list<ProductEnquiryItem> $items */',
4042
);
4143

42-
self::assertCount(1, $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
44+
self::assertCount(1, $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
4345
}
4446

4547
public function testErrorMessageContainsMethodAndParamName(): void
@@ -50,11 +52,11 @@ public function testErrorMessageContainsMethodAndParamName(): void
5052
'/** @param list<string> $records */',
5153
);
5254

53-
$errors = $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class));
55+
$errors = $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class]));
5456

5557
self::assertCount(1, $errors);
56-
self::assertStringContainsString('process()', (string) $errors[0]->getMessage());
57-
self::assertStringContainsString('$records', (string) $errors[0]->getMessage());
58+
self::assertStringContainsString('process()', $errors[0]->getMessage());
59+
self::assertStringContainsString('$records', $errors[0]->getMessage());
5860
}
5961

6062
public function testMultipleParamsAreNotFlagged(): void
@@ -65,21 +67,21 @@ public function testMultipleParamsAreNotFlagged(): void
6567
'/** @param list<string> $items */',
6668
);
6769

68-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
70+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
6971
}
7072

7173
public function testZeroParamsAreNotFlagged(): void
7274
{
7375
$method = $this->makeMethod('render', [], '/** no params */');
7476

75-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
77+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
7678
}
7779

7880
public function testNoDocblockIsNotFlagged(): void
7981
{
8082
$method = $this->makeMethod('render', [$this->makeArrayParam('items')], null);
8183

82-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
84+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
8385
}
8486

8587
public function testArrayDocblockIsNotFlagged(): void
@@ -90,7 +92,7 @@ public function testArrayDocblockIsNotFlagged(): void
9092
'/** @param array<string> $items */',
9193
);
9294

93-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
95+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
9496
}
9597

9698
public function testIterableDocblockIsNotFlagged(): void
@@ -101,7 +103,7 @@ public function testIterableDocblockIsNotFlagged(): void
101103
'/** @param iterable<string> $items */',
102104
);
103105

104-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
106+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
105107
}
106108

107109
public function testAlreadyVariadicIsNotFlagged(): void
@@ -113,15 +115,15 @@ public function testAlreadyVariadicIsNotFlagged(): void
113115
'/** @param list<string> $items */',
114116
);
115117

116-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
118+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
117119
}
118120

119121
public function testNonArrayTypeIsNotFlagged(): void
120122
{
121123
$param = new Param(new Variable('items'), null, new Identifier('string'));
122124
$method = $this->makeMethod('render', [$param], '/** @param list<string> $items */');
123125

124-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
126+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
125127
}
126128

127129
public function testNullableArrayTypeIsNotFlagged(): void
@@ -130,15 +132,15 @@ public function testNullableArrayTypeIsNotFlagged(): void
130132
$param = new Param(new Variable('items'), null, $nullableType);
131133
$method = $this->makeMethod('render', [$param], '/** @param list<string> $items */');
132134

133-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
135+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
134136
}
135137

136138
public function testUntypedParamIsNotFlagged(): void
137139
{
138140
$param = new Param(new Variable('items'));
139141
$method = $this->makeMethod('render', [$param], '/** @param list<string> $items */');
140142

141-
self::assertSame([], $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
143+
self::assertSame([], $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
142144
}
143145

144146
public function testNestedGenericListIsFlagged(): void
@@ -149,7 +151,7 @@ public function testNestedGenericListIsFlagged(): void
149151
'/** @param list<Type<A, B>> $items */',
150152
);
151153

152-
self::assertCount(1, $this->rule->processNode($method, $this->createStub(\PHPStan\Analyser\Scope::class)));
154+
self::assertCount(1, $this->rule->processNode($method, $this->createMockForIntersectionOfInterfaces([NodeCallbackInvoker::class, Scope::class])));
153155
}
154156

155157
/**

0 commit comments

Comments
 (0)