Skip to content

Commit 460000b

Browse files
Add regression tests
1 parent c898eea commit 460000b

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,9 @@ public static function selectFromArgs(
519519
$constantArrays = $type->getConstantArrays();
520520
if (count($constantArrays) > 0) {
521521
foreach ($constantArrays as $constantArray) {
522+
$values = $constantArray->getValueTypes();
522523
foreach ($constantArray->getKeyTypes() as $j => $keyType) {
523-
$valueType = $constantArray->getValueTypes()[$j];
524+
$valueType = $values[$j];
524525
$valueIndex = $keyType->getValue();
525526
if (is_string($valueIndex)) {
526527
$hasName = true;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8257;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
interface TreeMapper
8+
{
9+
/**
10+
* @template T of object
11+
*
12+
* @param string|class-string<T> $signature
13+
* @param mixed $source
14+
* @return (
15+
* $signature is class-string<T>
16+
* ? T
17+
* : mixed
18+
* )
19+
*/
20+
public function map(string $signature, $source);
21+
}
22+
23+
/** @var TreeMapper $tm */
24+
$tm;
25+
26+
class A {}
27+
28+
assertType('Bug8257\A', $tm->map(...[A::class, []]));

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3908,6 +3908,19 @@ public function testBug1501(): void
39083908
$this->analyse([__DIR__ . '/data/bug-1501.php'], []);
39093909
}
39103910

3911+
public function testBug7369(): void
3912+
{
3913+
$this->checkThisOnly = false;
3914+
$this->checkNullables = true;
3915+
$this->checkUnionTypes = true;
3916+
$this->analyse([__DIR__ . '/data/bug-7369.php'], [
3917+
[
3918+
'Cannot call method isAllowed() on bool.',
3919+
40,
3920+
],
3921+
]);
3922+
}
3923+
39113924
public function testBug11463(): void
39123925
{
39133926
$this->checkThisOnly = false;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug7369;
4+
5+
interface AccountInterface {}
6+
7+
interface AccessResultInterface {
8+
public function isAllowed(): bool;
9+
}
10+
11+
interface AccessibleInterface {
12+
13+
/**
14+
* @return ($return_as_object is true ? AccessResultInterface : bool)
15+
*/
16+
public function access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE);
17+
}
18+
19+
$class = new class() implements AccessibleInterface {
20+
/**
21+
* {@inheritDoc}
22+
*/
23+
public function access(
24+
string $operation,
25+
AccountInterface $account = null,
26+
bool $return_as_object = false
27+
) {
28+
if ($return_as_object) {
29+
return new class () implements AccessResultInterface {
30+
public function isAllowed(): bool {
31+
return true;
32+
}
33+
};
34+
}
35+
return false;
36+
}
37+
};
38+
39+
$class->access('view', null, true)->isAllowed();
40+
$class->access('view', null, false)->isAllowed();
41+
42+
$params = ['view', null, true];
43+
$class->access(...$params)->isAllowed();

0 commit comments

Comments
 (0)