Skip to content

Commit f74a18a

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents db66d83 + a2c0946 commit f74a18a

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

Diff for: src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
5959

6060
$isStrictComparison = $isStrictComparison
6161
|| $needleType->isEnum()->yes()
62-
|| $arrayValueType->isEnum()->yes();
62+
|| $arrayValueType->isEnum()->yes()
63+
|| ($needleType->isString()->yes() && $arrayValueType->isString()->yes())
64+
|| ($needleType->isInteger()->yes() && $arrayValueType->isInteger()->yes())
65+
|| ($needleType->isFloat()->yes() && $arrayValueType->isFloat()->yes())
66+
|| ($needleType->isBoolean()->yes() && $arrayValueType->isBoolean()->yes());
6367

6468
if ($arrayExpr instanceof Array_) {
6569
$types = null;

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -3558,7 +3558,6 @@ public function testDynamicCall(): void
35583558
$this->checkNullables = true;
35593559
$this->checkUnionTypes = true;
35603560
$this->checkExplicitMixed = true;
3561-
35623561
$this->analyse([__DIR__ . '/data/dynamic-call.php'], [
35633562
[
35643563
'Call to an undefined method MethodsDynamicCall\Foo::bar().',
@@ -3587,6 +3586,16 @@ public function testDynamicCall(): void
35873586
]);
35883587
}
35893588

3589+
public function testBug12884(): void
3590+
{
3591+
$this->checkThisOnly = false;
3592+
$this->checkNullables = true;
3593+
$this->checkUnionTypes = true;
3594+
$this->checkExplicitMixed = true;
3595+
3596+
$this->analyse([__DIR__ . '/data/bug-12884.php'], []);
3597+
}
3598+
35903599
public function testBu12793(): void
35913600
{
35923601
$this->checkThisOnly = false;

Diff for: tests/PHPStan/Rules/Methods/data/bug-12884.php

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug12884;
4+
5+
class LogLevel
6+
{
7+
const EMERGENCY = 'emergency';
8+
const ALERT = 'alert';
9+
const CRITICAL = 'critical';
10+
const ERROR = 'error';
11+
const WARNING = 'warning';
12+
const NOTICE = 'notice';
13+
const INFO = 'info';
14+
const DEBUG = 'debug';
15+
}
16+
17+
class HelloWorld
18+
{
19+
/** @param list<LogLevel::*> $levels */
20+
public function __construct(
21+
private LoggerInterface $logger,
22+
public array $levels = []
23+
) {}
24+
25+
public function log(string $level, string $message): void
26+
{
27+
if (!in_array($level, $this->levels, true)) {
28+
$level = LogLevel::INFO;
29+
}
30+
$this->logger->log($level, $message);
31+
}
32+
}
33+
34+
interface LoggerInterface
35+
{
36+
/**
37+
* @param 'emergency'|'alert'|'critical'|'error'|'warning'|'notice'|'info'|'debug' $level
38+
*/
39+
public function log($level, string|\Stringable $message): void;
40+
}

0 commit comments

Comments
 (0)