Skip to content

Commit d940d84

Browse files
authored
Merge branch refs/heads/1.10.x into 1.11.x
2 parents da620c7 + 9787895 commit d940d84

File tree

10 files changed

+45
-96
lines changed

10 files changed

+45
-96
lines changed

src/Type/CallableTypeHelper.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Reflection\ParametersAcceptor;
66
use PHPStan\TrinaryLogic;
7-
use PHPStan\Type\Generic\TemplateMixedType;
87
use function array_merge;
98
use function sprintf;
109

@@ -60,16 +59,7 @@ public static function isParametersAcceptorSuperTypeOf(
6059
}
6160

6261
if ($treatMixedAsAny) {
63-
if (
64-
$ourParameterType instanceof MixedType
65-
&& !$ourParameterType instanceof TemplateMixedType
66-
) {
67-
$isSuperType = new AcceptsResult(TrinaryLogic::createYes(), []);
68-
} elseif ($ourParameterType instanceof BenevolentUnionType) {
69-
$isSuperType = $theirParameter->getType()->acceptsWithReason($ourParameterType, true);
70-
} else {
71-
$isSuperType = new AcceptsResult($theirParameter->getType()->isSuperTypeOf($ourParameterType), []);
72-
}
62+
$isSuperType = $theirParameter->getType()->acceptsWithReason($ourParameterType, true);
7363
} else {
7464
$isSuperType = new AcceptsResult($theirParameter->getType()->isSuperTypeOf($ourParameterType), []);
7565
}

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -772,17 +772,15 @@ public function testDiscussion7124(): void
772772
}
773773

774774
$errors = $this->runAnalyse(__DIR__ . '/data/discussion-7124.php');
775-
$this->assertCount(5, $errors);
776-
$this->assertSame('Parameter #2 $callback of function array_filter expects callable(T): mixed, (callable(K): bool)|(callable(T): bool) given.', $errors[0]->getMessage());
777-
$this->assertSame(30, $errors[0]->getLine());
778-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int=): bool, Closure(int, bool): bool given.', $errors[1]->getMessage());
779-
$this->assertSame(38, $errors[1]->getLine());
780-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int=): bool, Closure(int): bool given.', $errors[2]->getMessage());
781-
$this->assertSame(45, $errors[2]->getLine());
782-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(int): bool, Closure(bool): bool given.', $errors[3]->getMessage());
783-
$this->assertSame(52, $errors[3]->getLine());
784-
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool): bool, Closure(int): bool given.', $errors[4]->getMessage());
785-
$this->assertSame(59, $errors[4]->getLine());
775+
$this->assertCount(4, $errors);
776+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int=): bool, Closure(int, bool): bool given.', $errors[0]->getMessage());
777+
$this->assertSame(38, $errors[0]->getLine());
778+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool, int=): bool, Closure(int): bool given.', $errors[1]->getMessage());
779+
$this->assertSame(45, $errors[1]->getLine());
780+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(int): bool, Closure(bool): bool given.', $errors[2]->getMessage());
781+
$this->assertSame(52, $errors[2]->getLine());
782+
$this->assertSame('Parameter #2 $callback of function Discussion7124\filter expects callable(bool): bool, Closure(int): bool given.', $errors[3]->getMessage());
783+
$this->assertSame(59, $errors[3]->getLine());
786784
}
787785

788786
public function testBug7214(): void

tests/PHPStan/Generics/data/varyingAcceptor-5.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
[
2+
{
3+
"message": "Parameter #1 $t1 of function PHPStan\\Generics\\VaryingAcceptor\\apply expects callable(PHPStan\\Generics\\VaryingAcceptor\\A): void, Closure(PHPStan\\Generics\\VaryingAcceptor\\B): void given.",
4+
"line": 36,
5+
"ignorable": true
6+
},
7+
{
8+
"message": "Parameter #2 $t1 of function PHPStan\\Generics\\VaryingAcceptor\\applyReversed expects callable(PHPStan\\Generics\\VaryingAcceptor\\A): void, Closure(PHPStan\\Generics\\VaryingAcceptor\\B): void given.",
9+
"line": 42,
10+
"ignorable": true
11+
},
212
{
313
"message": "Parameter #1 $closure of function PHPStan\\Generics\\VaryingAcceptor\\bar expects callable(callable(): string): string, callable(callable(): int): string given.",
414
"line": 55,

tests/PHPStan/Generics/data/varyingAcceptor-7.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/PHPStan/Levels/data/acceptTypes-5.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@
7474
"line": 227,
7575
"ignorable": true
7676
},
77+
{
78+
"message": "Parameter #1 $closure of method Levels\\AcceptTypes\\ClosureAccepts::doBar() expects Closure(Levels\\AcceptTypes\\FooInterface, int): Levels\\AcceptTypes\\FooInterface, Closure(Levels\\AcceptTypes\\FooImpl): Levels\\AcceptTypes\\FooImpl given.",
79+
"line": 238,
80+
"ignorable": true
81+
},
82+
{
83+
"message": "Parameter #1 $callable of method Levels\\AcceptTypes\\ClosureAccepts::doBaz() expects callable(Levels\\AcceptTypes\\FooInterface, int): Levels\\AcceptTypes\\FooInterface, Closure(Levels\\AcceptTypes\\FooImpl): Levels\\AcceptTypes\\FooImpl given.",
84+
"line": 239,
85+
"ignorable": true
86+
},
7787
{
7888
"message": "Parameter #1 $closure of method Levels\\AcceptTypes\\ClosureAccepts::doBar() expects Closure(Levels\\AcceptTypes\\FooInterface, int): Levels\\AcceptTypes\\FooInterface, Closure(Levels\\AcceptTypes\\FooInterface): Levels\\AcceptTypes\\ParentFooInterface given.",
7989
"line": 250,

tests/PHPStan/Levels/data/acceptTypes-7.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@
3434
"line": 167,
3535
"ignorable": true
3636
},
37-
{
38-
"message": "Parameter #1 $closure of method Levels\\AcceptTypes\\ClosureAccepts::doBar() expects Closure(Levels\\AcceptTypes\\FooInterface, int): Levels\\AcceptTypes\\FooInterface, Closure(Levels\\AcceptTypes\\FooImpl): Levels\\AcceptTypes\\FooImpl given.",
39-
"line": 238,
40-
"ignorable": true
41-
},
42-
{
43-
"message": "Parameter #1 $callable of method Levels\\AcceptTypes\\ClosureAccepts::doBaz() expects callable(Levels\\AcceptTypes\\FooInterface, int): Levels\\AcceptTypes\\FooInterface, Closure(Levels\\AcceptTypes\\FooImpl): Levels\\AcceptTypes\\FooImpl given.",
44-
"line": 239,
45-
"ignorable": true
46-
},
4737
{
4838
"message": "Parameter #1 $closure of method Levels\\AcceptTypes\\ClosureAccepts::doBar() expects Closure(Levels\\AcceptTypes\\FooInterface, int): Levels\\AcceptTypes\\FooInterface, (Closure(Levels\\AcceptTypes\\FooInterface, mixed, mixed): Levels\\AcceptTypes\\FooImpl)|(Closure(): Levels\\AcceptTypes\\FooInterface) given.",
4939
"line": 283,

tests/PHPStan/Levels/data/callableVariance-5.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
"line": 14,
55
"ignorable": true
66
},
7+
{
8+
"message": "Parameter #1 $cb of function Levels\\CallableVariance\\b expects callable(Levels\\CallableVariance\\B): void, Closure(Levels\\CallableVariance\\C): void given.",
9+
"line": 35,
10+
"ignorable": true
11+
},
12+
{
13+
"message": "Parameter #1 $cb of function Levels\\CallableVariance\\b expects callable(Levels\\CallableVariance\\B): void, callable(Levels\\CallableVariance\\C): void given.",
14+
"line": 39,
15+
"ignorable": true
16+
},
717
{
818
"message": "Parameter #1 $cb of function Levels\\CallableVariance\\c expects callable(): Levels\\CallableVariance\\B, Closure(): Levels\\CallableVariance\\A given.",
919
"line": 56,
@@ -14,6 +24,11 @@
1424
"line": 60,
1525
"ignorable": true
1626
},
27+
{
28+
"message": "Parameter #1 $cb of function Levels\\CallableVariance\\d expects callable(callable(): Levels\\CallableVariance\\B): Levels\\CallableVariance\\B, callable(callable(): Levels\\CallableVariance\\C): Levels\\CallableVariance\\C given.",
29+
"line": 81,
30+
"ignorable": true
31+
},
1732
{
1833
"message": "Parameter #1 $cb of function Levels\\CallableVariance\\d expects callable(callable(): Levels\\CallableVariance\\B): Levels\\CallableVariance\\B, callable(callable(): Levels\\CallableVariance\\A): Levels\\CallableVariance\\A given.",
1934
"line": 84,

tests/PHPStan/Levels/data/callableVariance-7.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2910,11 +2910,6 @@ public function testTrickyCallables(): void
29102910
'• Parameter #1 $key of passed callable is required but the parameter of accepting callable is optional. It might be called without it.
29112911
• Type int of parameter #1 $key of passed callable needs to be same or wider than parameter type int|string of accepting callable.',
29122912
],
2913-
[
2914-
'Parameter #1 $cb of method TrickyCallables\AcceptsFooParentCallable::sayHello() expects callable(TrickyCallables\FooParent): void, Closure(TrickyCallables\FooChild): void given.',
2915-
110,
2916-
'Type TrickyCallables\FooChild of parameter #1 $bar of passed callable needs to be same or wider than parameter type TrickyCallables\FooParent of accepting callable.',
2917-
],
29182913
]);
29192914
}
29202915

tests/PHPStan/Rules/Methods/data/tricky-callables.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,3 @@ function (TwoErrorsAtOnce $t): void {
8282
$filter = static fn (int $key): bool => true;
8383
$t->run($filter);
8484
};
85-
86-
class FooParent
87-
{
88-
89-
}
90-
91-
class FooChild extends FooParent
92-
{
93-
94-
}
95-
96-
class AcceptsFooParentCallable
97-
{
98-
99-
/**
100-
* @param callable(FooParent): void $cb
101-
*/
102-
public function sayHello(callable $cb): void
103-
{
104-
$cb(new FooParent());
105-
}
106-
107-
public function doFoo(): void
108-
{
109-
$hw = new self();
110-
$hw->sayHello(function (FooChild $bar): void {
111-
});
112-
}
113-
114-
}

0 commit comments

Comments
 (0)