Skip to content

Commit 8bbf9bb

Browse files
phpstan-botclaude
authored andcommitted
Move CallMethodsRule tests for array&callable to separate file and add constant array test cases
Test callable&array passed to methods expecting constant array types: - array{string, string} => Error (object at index 0 is not string) - array{object|string, string} => No error (matches callable-array shape) - array{object|string, string, string} => Error (callable-array has 2 elements, not 3) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 20dccde commit 8bbf9bb

4 files changed

Lines changed: 71 additions & 34 deletions

File tree

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4030,14 +4030,30 @@ public function testBug14549(): void
40304030
$this->checkThisOnly = false;
40314031
$this->checkNullables = true;
40324032
$this->checkUnionTypes = true;
4033-
$this->analyse([__DIR__ . '/data/bug-14549.php'], [
4033+
$this->analyse([__DIR__ . '/data/bug-14549-bis.php'], [
40344034
[
4035-
'Parameter #1 $param of method Bug14549\Foo::call() expects array<int>, array&callable given.',
4036-
67,
4035+
'Parameter #1 $param of method Bug14549Bis\Foo::callArrayInt() expects array<int>, array&callable given.',
4036+
33,
40374037
],
40384038
[
4039-
'Parameter #1 $param of method Bug14549\Foo::call() expects array<int>, array&callable given.',
4040-
75,
4039+
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayStringString() expects array{string, string}, array&callable(): mixed given.',
4040+
34,
4041+
],
4042+
[
4043+
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayObjectOrStringStringString() expects array{object|string, string, string}, array&callable(): mixed given.',
4044+
36,
4045+
],
4046+
[
4047+
'Parameter #1 $param of method Bug14549Bis\Foo::callArrayInt() expects array<int>, array&callable given.',
4048+
44,
4049+
],
4050+
[
4051+
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayStringString() expects array{string, string}, array&callable(): mixed given.',
4052+
45,
4053+
],
4054+
[
4055+
'Parameter #1 $param of method Bug14549Bis\Foo::callConstantArrayObjectOrStringStringString() expects array{object|string, string, string}, array&callable(): mixed given.',
4056+
47,
40414057
],
40424058
]);
40434059
}

tests/PHPStan/Rules/Methods/MissingMethodParameterTypehintRuleTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,6 @@ public function testBug14549(): void
169169
'Method Bug14549\Foo::doBaz() has parameter $task with no signature specified for callable.',
170170
53,
171171
],
172-
[
173-
'Method Bug14549\Foo::doCallWithCallableArray() has parameter $task with no signature specified for callable.',
174-
65,
175-
],
176-
[
177-
'Method Bug14549\Foo::doCallWithCallableAndArray() has parameter $task with no signature specified for callable.',
178-
73,
179-
],
180172
]);
181173
}
182174

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Bug14549Bis;
4+
5+
class Foo
6+
{
7+
8+
/** @param array<int> $param */
9+
public function callArrayInt(array $param): void
10+
{
11+
}
12+
13+
/** @param array{string, string} $param */
14+
public function callConstantArrayStringString(array $param): void
15+
{
16+
}
17+
18+
/** @param array{object|string, string} $param */
19+
public function callConstantArrayObjectOrStringString(array $param): void
20+
{
21+
}
22+
23+
/** @param array{object|string, string, string} $param */
24+
public function callConstantArrayObjectOrStringStringString(array $param): void
25+
{
26+
}
27+
28+
/**
29+
* @param callable-array $task
30+
*/
31+
public function doCallWithCallableArray(array $task): void
32+
{
33+
$this->callArrayInt($task);
34+
$this->callConstantArrayStringString($task);
35+
$this->callConstantArrayObjectOrStringString($task);
36+
$this->callConstantArrayObjectOrStringStringString($task);
37+
}
38+
39+
/**
40+
* @param callable&array $task
41+
*/
42+
public function doCallWithCallableAndArray(array $task): void
43+
{
44+
$this->callArrayInt($task);
45+
$this->callConstantArrayStringString($task);
46+
$this->callConstantArrayObjectOrStringString($task);
47+
$this->callConstantArrayObjectOrStringStringString($task);
48+
}
49+
50+
}

tests/PHPStan/Rules/Methods/data/bug-14549.php

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,6 @@ public function doBaz(array $task): void
5454
{
5555
}
5656

57-
/** @param array<int> $param */
58-
public function call(array $param): void
59-
{
60-
}
61-
62-
/**
63-
* @param callable-array $task
64-
*/
65-
public function doCallWithCallableArray(array $task): void
66-
{
67-
$this->call($task);
68-
}
69-
70-
/**
71-
* @param callable&array $task
72-
*/
73-
public function doCallWithCallableAndArray(array $task): void
74-
{
75-
$this->call($task);
76-
}
77-
7857
}
7958

8059

0 commit comments

Comments
 (0)