From 7e13ef2ab39fc89295b5fd3e1e8f1defa8c2a7b6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 31 Jul 2021 08:52:01 +0200 Subject: [PATCH 01/12] array_fill() always returns false on negative 2nd arg --- src/Type/Php/ArrayFillFunctionReturnTypeExtension.php | 7 +++++++ tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php | 8 ++++++++ tests/PHPStan/Analyser/data/array-functions.php | 3 +++ 3 files changed, 18 insertions(+) diff --git a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php index c1a8c168dd..256b34d143 100644 --- a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php @@ -9,7 +9,9 @@ use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\ArrayType; use PHPStan\Type\Constant\ConstantArrayTypeBuilder; +use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\Constant\ConstantIntegerType; +use PHPStan\Type\IntegerRangeType; use PHPStan\Type\IntegerType; use PHPStan\Type\IntersectionType; use PHPStan\Type\Type; @@ -34,6 +36,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $numberType = $scope->getType($functionCall->args[1]->value); $valueType = $scope->getType($functionCall->args[2]->value); + // check against negative-int + if (IntegerRangeType::fromInterval(null, -1)->isSuperTypeOf($numberType)->yes()) { + return new ConstantBooleanType(false); + } + if ( $startIndexType instanceof ConstantIntegerType && $numberType instanceof ConstantIntegerType diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 27983a2c6a..ac799e0ed3 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -5104,6 +5104,14 @@ public function dataArrayFunctions(): array 'array(1)', '$filledIntegersWithKeys', ], + [ + 'false', + '$filledAlwaysFalse', + ], + [ + 'false', + '$filledNegativeConstAlwaysFalse', + ], [ 'array(1, 2)', 'array_keys($integerKeys)', diff --git a/tests/PHPStan/Analyser/data/array-functions.php b/tests/PHPStan/Analyser/data/array-functions.php index 752fe4fd07..34d20809a1 100644 --- a/tests/PHPStan/Analyser/data/array-functions.php +++ b/tests/PHPStan/Analyser/data/array-functions.php @@ -38,6 +38,9 @@ $filledIntegers = array_fill(0, 5, 1); $filledIntegersWithKeys = array_fill_keys([0], 1); +/** @var negative-int $negInt */ +$filledAlwaysFalse = array_fill(0, $negInt, 1); +$filledNegativeConstAlwaysFalse = array_fill(0, -5, 1); $integerKeys = [ 1 => 'foo', From a60c9af3357e30e2ad54e867dd202d5ac3c75925 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 17 Aug 2021 20:51:55 +0200 Subject: [PATCH 02/12] cover integer-range in array_fill --- .../ArrayFillFunctionReturnTypeExtension.php | 30 +++++++++++++++---- .../Analyser/LegacyNodeScopeResolverTest.php | 12 ++++++-- .../PHPStan/Analyser/data/array-functions.php | 3 ++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php index 256b34d143..f7896553d3 100644 --- a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php @@ -4,6 +4,7 @@ use PhpParser\Node\Expr\FuncCall; use PHPStan\Analyser\Scope; +use PHPStan\Php\PhpVersion; use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\ParametersAcceptorSelector; use PHPStan\Type\Accessory\NonEmptyArrayType; @@ -14,13 +15,21 @@ use PHPStan\Type\IntegerRangeType; use PHPStan\Type\IntegerType; use PHPStan\Type\IntersectionType; +use PHPStan\Type\NeverType; use PHPStan\Type\Type; +use PHPStan\Type\TypeCombinator; class ArrayFillFunctionReturnTypeExtension implements \PHPStan\Type\DynamicFunctionReturnTypeExtension { - private const MAX_SIZE_USE_CONSTANT_ARRAY = 100; + private PhpVersion $phpVersion; + + public function __construct(PhpVersion $phpVersion) + { + $this->phpVersion = $phpVersion; + } + public function isFunctionSupported(FunctionReflection $functionReflection): bool { return $functionReflection->getName() === 'array_fill'; @@ -36,8 +45,20 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $numberType = $scope->getType($functionCall->args[1]->value); $valueType = $scope->getType($functionCall->args[2]->value); - // check against negative-int + if ($numberType instanceof IntegerRangeType) { + if ($numberType->getMin() < 0) { + return TypeCombinator::union( + new ArrayType(new IntegerType(), $valueType), + new ConstantBooleanType(false) + ); + } + } + + // check against negative-int, which is not allowed if (IntegerRangeType::fromInterval(null, -1)->isSuperTypeOf($numberType)->yes()) { + if ($this->phpVersion->getVersionId() >= 80000) { + return new NeverType(); + } return new ConstantBooleanType(false); } @@ -63,10 +84,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, return $arrayBuilder->getArray(); } - if ( - $numberType instanceof ConstantIntegerType - && $numberType->getValue() > 0 - ) { + if (IntegerRangeType::fromInterval(1, null)->isSuperTypeOf($numberType)->yes()) { return new IntersectionType([ new ArrayType(new IntegerType(), $valueType), new NonEmptyArrayType(), diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index ac799e0ed3..9a7fd5ce97 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -5105,13 +5105,21 @@ public function dataArrayFunctions(): array '$filledIntegersWithKeys', ], [ - 'false', + PHP_VERSION_ID < 80000 ? 'false' : '*NEVER*', '$filledAlwaysFalse', ], [ - 'false', + PHP_VERSION_ID < 80000 ? 'false' : '*NEVER*', '$filledNegativeConstAlwaysFalse', ], + [ + 'array|false', + '$filledByMaybeNegativeRange', + ], + [ + 'array&nonEmpty', + '$filledByPositiveRange', + ], [ 'array(1, 2)', 'array_keys($integerKeys)', diff --git a/tests/PHPStan/Analyser/data/array-functions.php b/tests/PHPStan/Analyser/data/array-functions.php index 34d20809a1..fe379aa24d 100644 --- a/tests/PHPStan/Analyser/data/array-functions.php +++ b/tests/PHPStan/Analyser/data/array-functions.php @@ -41,6 +41,9 @@ /** @var negative-int $negInt */ $filledAlwaysFalse = array_fill(0, $negInt, 1); $filledNegativeConstAlwaysFalse = array_fill(0, -5, 1); +/** @var int<-3, 5> $maybeNegRange */ +$filledByMaybeNegativeRange = array_fill(0, $maybeNegRange, 1); +$filledByPositiveRange = array_fill(0, rand(3, 5), 1); $integerKeys = [ 1 => 'foo', From f41fe1059aae16436d559f4791ea336af02622e9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 17 Aug 2021 20:55:29 +0200 Subject: [PATCH 03/12] adjust functionMap php8-delta --- resources/functionMap_php80delta.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index f1735f2a4e..c0ee179eb1 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -146,6 +146,7 @@ 'old' => [ 'array_combine' => ['associative-array|false', 'keys'=>'string[]|int[]', 'values'=>'array'], + 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'0|positive', 'val'=>'mixed'], 'bcdiv' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['?string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], From de4a669849bc70af390cd13d4aba1ffbd5beb22a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 17 Aug 2021 20:56:18 +0200 Subject: [PATCH 04/12] fix CS --- src/Type/Php/ArrayFillFunctionReturnTypeExtension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php index f7896553d3..a102a0a384 100644 --- a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php @@ -21,6 +21,7 @@ class ArrayFillFunctionReturnTypeExtension implements \PHPStan\Type\DynamicFunctionReturnTypeExtension { + private const MAX_SIZE_USE_CONSTANT_ARRAY = 100; private PhpVersion $phpVersion; From 49ca5f0cff52ce193867a95ff6d7c8c716cf3db6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 17 Aug 2021 21:09:10 +0200 Subject: [PATCH 05/12] added more testcases --- tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php | 8 ++++++++ tests/PHPStan/Analyser/data/array-functions.php | 3 +++ 2 files changed, 11 insertions(+) diff --git a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php index 9a7fd5ce97..6971ea40f0 100644 --- a/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php +++ b/tests/PHPStan/Analyser/LegacyNodeScopeResolverTest.php @@ -5100,10 +5100,18 @@ public function dataArrayFunctions(): array 'array(1, 1, 1, 1, 1)', '$filledIntegers', ], + [ + 'array()', + '$emptyFilled', + ], [ 'array(1)', '$filledIntegersWithKeys', ], + [ + 'array&nonEmpty', + '$filledNonEmptyArray', + ], [ PHP_VERSION_ID < 80000 ? 'false' : '*NEVER*', '$filledAlwaysFalse', diff --git a/tests/PHPStan/Analyser/data/array-functions.php b/tests/PHPStan/Analyser/data/array-functions.php index fe379aa24d..15d7252487 100644 --- a/tests/PHPStan/Analyser/data/array-functions.php +++ b/tests/PHPStan/Analyser/data/array-functions.php @@ -37,9 +37,12 @@ }, 1); $filledIntegers = array_fill(0, 5, 1); +$emptyFilled = array_fill(3, 0, 'banana'); $filledIntegersWithKeys = array_fill_keys([0], 1); /** @var negative-int $negInt */ $filledAlwaysFalse = array_fill(0, $negInt, 1); +/** @var positive-int $posInt */ +$filledNonEmptyArray = array_fill(0, $posInt, 'foo'); $filledNegativeConstAlwaysFalse = array_fill(0, -5, 1); /** @var int<-3, 5> $maybeNegRange */ $filledByMaybeNegativeRange = array_fill(0, $maybeNegRange, 1); From 3783f9085a24d46b1908a58b5bec1cac9507d95d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 18 Aug 2021 21:02:53 +0200 Subject: [PATCH 06/12] try to fix function map --- resources/functionMap_php80delta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index c0ee179eb1..298ba01a16 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -22,6 +22,7 @@ return [ 'new' => [ 'array_combine' => ['associative-array', 'keys'=>'string[]|int[]', 'values'=>'array'], + 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'0|positive', 'val'=>'mixed'], 'bcdiv' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], @@ -146,7 +147,6 @@ 'old' => [ 'array_combine' => ['associative-array|false', 'keys'=>'string[]|int[]', 'values'=>'array'], - 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'0|positive', 'val'=>'mixed'], 'bcdiv' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['?string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], From b97428599f90c2f040fa6e75b77bf56313c16b8b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 19 Aug 2021 17:49:31 +0200 Subject: [PATCH 07/12] utilize throwsValueErrorForInternalFunctions --- src/Type/Php/ArrayFillFunctionReturnTypeExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php index a102a0a384..ab42e9a5d9 100644 --- a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php @@ -57,7 +57,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, // check against negative-int, which is not allowed if (IntegerRangeType::fromInterval(null, -1)->isSuperTypeOf($numberType)->yes()) { - if ($this->phpVersion->getVersionId() >= 80000) { + if ($this->phpVersion->throwsValueErrorForInternalFunctions()) { return new NeverType(); } return new ConstantBooleanType(false); From a571745b2ae601c6129ed6dd337f4a3a3833d1c3 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 19 Aug 2021 18:05:51 +0200 Subject: [PATCH 08/12] adjusted function-map --- resources/functionMap.php | 2 +- resources/functionMap_php80delta.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index 9f7282a0a0..9cdcae2ac5 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -271,7 +271,7 @@ 'array_diff_uassoc\'1' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable'], 'array_diff_ukey' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'key_comp_func'=>'callable(mixed,mixed):int'], 'array_diff_ukey\'1' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable(mixed,mixed):int'], -'array_fill' => ['array', 'start_key'=>'int', 'num'=>'int', 'val'=>'mixed'], +'array_fill' => ['array', 'start_index'=>'int', 'count'=>'int', 'value'=>'mixed'], 'array_fill_keys' => ['array', 'keys'=>'array', 'val'=>'mixed'], 'array_filter' => ['array', 'input'=>'array', 'callback='=>'callable(mixed,mixed):bool|callable(mixed):bool', 'flag='=>'int'], 'array_flip' => ['array', 'input'=>'array'], diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index 298ba01a16..88a903ed81 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -22,7 +22,7 @@ return [ 'new' => [ 'array_combine' => ['associative-array', 'keys'=>'string[]|int[]', 'values'=>'array'], - 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'0|positive', 'val'=>'mixed'], + 'array_fill' => ['array', 'start_index'=>'int', 'count'=>'0|positive-int', 'value'=>'mixed'], 'bcdiv' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], @@ -147,6 +147,7 @@ 'old' => [ 'array_combine' => ['associative-array|false', 'keys'=>'string[]|int[]', 'values'=>'array'], + 'array_fill' => ['array', 'start_index'=>'int', 'count'=>'int', 'value'=>'mixed'], 'bcdiv' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['?string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], From 5b669cccffe49d9cd1615a0bd216fdc401d47bbe Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 19 Aug 2021 18:14:54 +0200 Subject: [PATCH 09/12] pass positive-int to array_fill() --- src/File/ParentDirectoryRelativePathHelper.php | 4 ++++ tests/PHPStan/Parallel/SchedulerTest.php | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/File/ParentDirectoryRelativePathHelper.php b/src/File/ParentDirectoryRelativePathHelper.php index 306f8f0dbf..3500260918 100644 --- a/src/File/ParentDirectoryRelativePathHelper.php +++ b/src/File/ParentDirectoryRelativePathHelper.php @@ -2,6 +2,7 @@ namespace PHPStan\File; +use PHPStan\ShouldNotHappenException; use function array_slice; use function str_replace; @@ -54,6 +55,9 @@ public function getFilenameParts(string $filename): array } $dotsCount = $parentPartsCount - $i; + if ($dotsCount < 0) { + throw new ShouldNotHappenException(); + } return array_merge(array_fill(0, $dotsCount, '..'), array_slice($filenameParts, $i)); } diff --git a/tests/PHPStan/Parallel/SchedulerTest.php b/tests/PHPStan/Parallel/SchedulerTest.php index e029e06d9b..df9906b1e6 100644 --- a/tests/PHPStan/Parallel/SchedulerTest.php +++ b/tests/PHPStan/Parallel/SchedulerTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Parallel; +use PHPStan\ShouldNotHappenException; use PHPUnit\Framework\TestCase; class SchedulerTest extends TestCase @@ -87,6 +88,10 @@ public function testSchedule( array $expectedJobSizes ): void { + if ($numberOfFiles < 0) { + throw new ShouldNotHappenException(); + } + $files = array_fill(0, $numberOfFiles, 'file.php'); $scheduler = new Scheduler($jobSize, $maximumNumberOfProcesses, $minimumNumberOfJobsPerProcess); $schedule = $scheduler->scheduleWork($cpuCores, $files); From 5fc8496234569399d757fbe0b81ee94cf4e2e898 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 19 Aug 2021 18:17:38 +0200 Subject: [PATCH 10/12] fix CS --- src/File/ParentDirectoryRelativePathHelper.php | 3 +-- tests/PHPStan/Parallel/SchedulerTest.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/File/ParentDirectoryRelativePathHelper.php b/src/File/ParentDirectoryRelativePathHelper.php index 3500260918..b88c930758 100644 --- a/src/File/ParentDirectoryRelativePathHelper.php +++ b/src/File/ParentDirectoryRelativePathHelper.php @@ -2,7 +2,6 @@ namespace PHPStan\File; -use PHPStan\ShouldNotHappenException; use function array_slice; use function str_replace; @@ -56,7 +55,7 @@ public function getFilenameParts(string $filename): array $dotsCount = $parentPartsCount - $i; if ($dotsCount < 0) { - throw new ShouldNotHappenException(); + throw new \PHPStan\ShouldNotHappenException(); } return array_merge(array_fill(0, $dotsCount, '..'), array_slice($filenameParts, $i)); diff --git a/tests/PHPStan/Parallel/SchedulerTest.php b/tests/PHPStan/Parallel/SchedulerTest.php index df9906b1e6..45573d9a32 100644 --- a/tests/PHPStan/Parallel/SchedulerTest.php +++ b/tests/PHPStan/Parallel/SchedulerTest.php @@ -2,7 +2,6 @@ namespace PHPStan\Parallel; -use PHPStan\ShouldNotHappenException; use PHPUnit\Framework\TestCase; class SchedulerTest extends TestCase @@ -89,7 +88,7 @@ public function testSchedule( ): void { if ($numberOfFiles < 0) { - throw new ShouldNotHappenException(); + throw new \PHPStan\ShouldNotHappenException(); } $files = array_fill(0, $numberOfFiles, 'file.php'); From 1cd28f4587aafa9f38b1cbc18cdf9f129ac5a3d9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Aug 2021 12:09:58 +0200 Subject: [PATCH 11/12] revert naming changes --- resources/functionMap.php | 2 +- resources/functionMap_php80delta.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/functionMap.php b/resources/functionMap.php index 9cdcae2ac5..9f7282a0a0 100644 --- a/resources/functionMap.php +++ b/resources/functionMap.php @@ -271,7 +271,7 @@ 'array_diff_uassoc\'1' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable'], 'array_diff_ukey' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'key_comp_func'=>'callable(mixed,mixed):int'], 'array_diff_ukey\'1' => ['array', 'arr1'=>'array', 'arr2'=>'array', 'arr3'=>'array', 'arg4'=>'array|callable(mixed,mixed):int', '...rest='=>'array|callable(mixed,mixed):int'], -'array_fill' => ['array', 'start_index'=>'int', 'count'=>'int', 'value'=>'mixed'], +'array_fill' => ['array', 'start_key'=>'int', 'num'=>'int', 'val'=>'mixed'], 'array_fill_keys' => ['array', 'keys'=>'array', 'val'=>'mixed'], 'array_filter' => ['array', 'input'=>'array', 'callback='=>'callable(mixed,mixed):bool|callable(mixed):bool', 'flag='=>'int'], 'array_flip' => ['array', 'input'=>'array'], diff --git a/resources/functionMap_php80delta.php b/resources/functionMap_php80delta.php index 88a903ed81..a90cd9af3d 100644 --- a/resources/functionMap_php80delta.php +++ b/resources/functionMap_php80delta.php @@ -22,7 +22,7 @@ return [ 'new' => [ 'array_combine' => ['associative-array', 'keys'=>'string[]|int[]', 'values'=>'array'], - 'array_fill' => ['array', 'start_index'=>'int', 'count'=>'0|positive-int', 'value'=>'mixed'], + 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'0|positive-int', 'val'=>'mixed'], 'bcdiv' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], @@ -147,7 +147,7 @@ 'old' => [ 'array_combine' => ['associative-array|false', 'keys'=>'string[]|int[]', 'values'=>'array'], - 'array_fill' => ['array', 'start_index'=>'int', 'count'=>'int', 'value'=>'mixed'], + 'array_fill' => ['array', 'start_key'=>'int', 'num'=>'int', 'val'=>'mixed'], 'bcdiv' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcmod' => ['?string', 'dividend'=>'string', 'divisor'=>'string', 'scale='=>'int'], 'bcpowmod' => ['?string', 'base'=>'string', 'exponent'=>'string', 'modulus'=>'string', 'scale='=>'int'], From af9196dddde5b4997ee5d40b737888aa4cb73d44 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Fri, 20 Aug 2021 12:11:38 +0200 Subject: [PATCH 12/12] use `0|positive-int` instead --- tests/PHPStan/Parallel/SchedulerTest.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/PHPStan/Parallel/SchedulerTest.php b/tests/PHPStan/Parallel/SchedulerTest.php index 45573d9a32..538dd69016 100644 --- a/tests/PHPStan/Parallel/SchedulerTest.php +++ b/tests/PHPStan/Parallel/SchedulerTest.php @@ -73,7 +73,7 @@ public function dataSchedule(): array * @param int $maximumNumberOfProcesses * @param int $minimumNumberOfJobsPerProcess * @param int $jobSize - * @param int $numberOfFiles + * @param 0|positive-int $numberOfFiles * @param int $expectedNumberOfProcesses * @param array $expectedJobSizes */ @@ -87,10 +87,6 @@ public function testSchedule( array $expectedJobSizes ): void { - if ($numberOfFiles < 0) { - throw new \PHPStan\ShouldNotHappenException(); - } - $files = array_fill(0, $numberOfFiles, 'file.php'); $scheduler = new Scheduler($jobSize, $maximumNumberOfProcesses, $minimumNumberOfJobsPerProcess); $schedule = $scheduler->scheduleWork($cpuCores, $files);