Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1425,12 +1425,7 @@ parameters:

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantScalarType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantScalarValue\\(\\) or Type\\:\\:getConstantScalarTypes\\(\\) or Type\\:\\:getConstantScalarValues\\(\\) instead\\.$#"
count: 4
path: src/Type/Php/MinMaxFunctionReturnTypeExtension.php

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\ConstantType is error\\-prone and deprecated\\. Use Type\\:\\:isConstantValue\\(\\) or Type\\:\\:generalize\\(\\) instead\\.$#"
count: 1
count: 2
path: src/Type/Php/MinMaxFunctionReturnTypeExtension.php

-
Expand Down
17 changes: 8 additions & 9 deletions src/Type/Php/MinMaxFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\ConstantType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;
Expand Down Expand Up @@ -152,16 +151,16 @@ private function processType(
{
$resultType = null;
foreach ($types as $type) {
if (!$type instanceof ConstantType) {
return TypeCombinator::union(...$types);
}

if ($resultType === null) {
$resultType = $type;
continue;
}

$compareResult = $this->compareTypes($resultType, $type);
if ($compareResult === null) {
return TypeCombinator::union(...$types);
}

if ($functionName === 'min') {
if ($compareResult === $type) {
$resultType = $type;
Expand All @@ -186,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
Loading