Skip to content

Commit 69770e5

Browse files
committed
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
2 parents 19649e4 + 537219b commit 69770e5

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,7 @@ parameters:
15601560
-
15611561
message: '#^Doing instanceof PHPStan\\Type\\ConstantScalarType is error\-prone and deprecated\. Use Type\:\:isConstantScalarValue\(\) or Type\:\:getConstantScalarTypes\(\) or Type\:\:getConstantScalarValues\(\) instead\.$#'
15621562
identifier: phpstanApi.instanceofType
1563-
count: 4
1563+
count: 2
15641564
path: src/Type/Php/MinMaxFunctionReturnTypeExtension.php
15651565

15661566
-

src/Type/Php/MinMaxFunctionReturnTypeExtension.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ private function processType(
151151
{
152152
$resultType = null;
153153
foreach ($types as $type) {
154-
if (!$type->isConstantValue()->yes()) {
155-
return TypeCombinator::union(...$types);
156-
}
157154
if ($resultType === null) {
158155
$resultType = $type;
159156
continue;
@@ -188,15 +185,15 @@ private function compareTypes(
188185
): ?Type
189186
{
190187
if (
191-
$firstType->isConstantArray()->yes()
192-
&& $secondType instanceof ConstantScalarType
188+
$firstType->isArray()->yes()
189+
&& $secondType->isConstantScalarValue()->yes()
193190
) {
194191
return $secondType;
195192
}
196193

197194
if (
198-
$firstType instanceof ConstantScalarType
199-
&& $secondType->isConstantArray()->yes()
195+
$firstType->isConstantScalarValue()->yes()
196+
&& $secondType->isArray()->yes()
200197
) {
201198
return $firstType;
202199
}

tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,14 +2363,42 @@ public function dataBinaryOperations(): array
23632363
'array<int>',
23642364
'max($arrayOfUnknownIntegers, $arrayOfUnknownIntegers)',
23652365
],
2366-
/*[
2367-
'array(1, 1, 1, 1)',
2366+
[
2367+
'array{1, 1, 1, 1}',
23682368
'max(array(2, 2, 2), 5, array(1, 1, 1, 1))',
23692369
],
2370+
[
2371+
'array{int, int, int}',
2372+
'max($arrayOfIntegers, 5)',
2373+
],
23702374
[
23712375
'array<int>',
2376+
'max($arrayOfUnknownIntegers, 5)',
2377+
],
2378+
[
2379+
'array<int>|int', // could be array<int>
23722380
'max($arrayOfUnknownIntegers, $integer, $arrayOfUnknownIntegers)',
2373-
],*/
2381+
],
2382+
[
2383+
'array<int>',
2384+
'max($arrayOfUnknownIntegers, $conditionalInt)',
2385+
],
2386+
[
2387+
'5',
2388+
'min($arrayOfIntegers, 5)',
2389+
],
2390+
[
2391+
'5',
2392+
'min($arrayOfUnknownIntegers, 5)',
2393+
],
2394+
[
2395+
'1|2',
2396+
'min($arrayOfUnknownIntegers, $conditionalInt)',
2397+
],
2398+
[
2399+
'5',
2400+
'min(array(2, 2, 2), 5, array(1, 1, 1, 1))',
2401+
],
23742402
[
23752403
'1.1',
23762404
'min(...[1.1, 2.2, 3.3])',

0 commit comments

Comments
 (0)