Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.12.x' into 2.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 19, 2025
2 parents 19649e4 + 537219b commit 69770e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ parameters:
-
message: '#^Doing instanceof PHPStan\\Type\\ConstantScalarType is error\-prone and deprecated\. Use Type\:\:isConstantScalarValue\(\) or Type\:\:getConstantScalarTypes\(\) or Type\:\:getConstantScalarValues\(\) instead\.$#'
identifier: phpstanApi.instanceofType
count: 4
count: 2
path: src/Type/Php/MinMaxFunctionReturnTypeExtension.php

-
Expand Down
11 changes: 4 additions & 7 deletions src/Type/Php/MinMaxFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ private function processType(
{
$resultType = null;
foreach ($types as $type) {
if (!$type->isConstantValue()->yes()) {
return TypeCombinator::union(...$types);
}
if ($resultType === null) {
$resultType = $type;
continue;
Expand Down Expand Up @@ -188,15 +185,15 @@ private function compareTypes(
): ?Type
{
if (
$firstType->isConstantArray()->yes()
&& $secondType instanceof ConstantScalarType
$firstType->isArray()->yes()
&& $secondType->isConstantScalarValue()->yes()
) {
return $secondType;
}

if (
$firstType instanceof ConstantScalarType
&& $secondType->isConstantArray()->yes()
$firstType->isConstantScalarValue()->yes()
&& $secondType->isArray()->yes()
) {
return $firstType;
}
Expand Down
34 changes: 31 additions & 3 deletions tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2363,14 +2363,42 @@ public function dataBinaryOperations(): array
'array<int>',
'max($arrayOfUnknownIntegers, $arrayOfUnknownIntegers)',
],
/*[
'array(1, 1, 1, 1)',
[
'array{1, 1, 1, 1}',
'max(array(2, 2, 2), 5, array(1, 1, 1, 1))',
],
[
'array{int, int, int}',
'max($arrayOfIntegers, 5)',
],
[
'array<int>',
'max($arrayOfUnknownIntegers, 5)',
],
[
'array<int>|int', // could be array<int>
'max($arrayOfUnknownIntegers, $integer, $arrayOfUnknownIntegers)',
],*/
],
[
'array<int>',
'max($arrayOfUnknownIntegers, $conditionalInt)',
],
[
'5',
'min($arrayOfIntegers, 5)',
],
[
'5',
'min($arrayOfUnknownIntegers, 5)',
],
[
'1|2',
'min($arrayOfUnknownIntegers, $conditionalInt)',
],
[
'5',
'min(array(2, 2, 2), 5, array(1, 1, 1, 1))',
],
[
'1.1',
'min(...[1.1, 2.2, 3.3])',
Expand Down

0 comments on commit 69770e5

Please sign in to comment.