Skip to content
Draft
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
20 changes: 10 additions & 10 deletions resources/functionMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2932,7 +2932,7 @@
'ffmpeg_movie::hasAudio' => ['bool'],
'ffmpeg_movie::hasVideo' => ['bool'],
'fgetc' => ['string|false', 'fp'=>'resource'],
'fgetcsv' => ['list<string>|array{0: null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'fgetcsv' => ['list<string>|list{null}|false|null', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'fgets' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int'],
'fgetss' => ['string|false', 'fp'=>'resource', 'length='=>'0|positive-int', 'allowable_tags='=>'string'],
'file' => ['list<string>|false', 'filename'=>'string', 'flags='=>'int-mask<FILE_USE_INCLUDE_PATH|FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES|FILE_NO_DEFAULT_CONTEXT>', 'context='=>'resource'],
Expand Down Expand Up @@ -4534,8 +4534,8 @@
'image_type_to_mime_type' => ['string', 'imagetype'=>'int'],
'imageaffine' => ['resource|false', 'src'=>'resource', 'affine'=>'array', 'clip='=>'array'],
'imageaffineconcat' => ['array', 'm1'=>'array', 'm2'=>'array'],
'imageaffinematrixconcat' => ['array{0:float,1:float,2:float,3:float,4:float,5:float}|false', 'm1'=>'array', 'm2'=>'array'],
'imageaffinematrixget' => ['array{0:float,1:float,2:float,3:float,4:float,5:float}|false', 'type'=>'int', 'options'=>'array|float'],
'imageaffinematrixconcat' => ['list{float,float,float,float,float,float}|false', 'm1'=>'array', 'm2'=>'array'],
'imageaffinematrixget' => ['list{float,float,float,float,float,float}|false', 'type'=>'int', 'options'=>'array|float'],
'imagealphablending' => ['bool', 'im'=>'resource', 'on'=>'bool'],
'imageantialias' => ['bool', 'im'=>'resource', 'on'=>'bool'],
'imagearc' => ['bool', 'im'=>'resource', 'cx'=>'int', 'cy'=>'int', 'w'=>'int', 'h'=>'int', 's'=>'int', 'e'=>'int', 'col'=>'int'],
Expand Down Expand Up @@ -4682,9 +4682,9 @@
'Imagick::colorMatrixImage' => ['bool', 'color_matrix'=>'array'],
'Imagick::combineImages' => ['Imagick', 'channeltype'=>'Imagick::CHANNEL_*'],
'Imagick::commentImage' => ['bool', 'comment'=>'string'],
'Imagick::compareImageChannels' => ['array{Imagick,float}', 'image'=>'imagick', 'channeltype'=>'Imagick::CHANNEL_*', 'metrictype'=>'Imagick::METRIC_*'],
'Imagick::compareImageChannels' => ['list{Imagick,float}', 'image'=>'imagick', 'channeltype'=>'Imagick::CHANNEL_*', 'metrictype'=>'Imagick::METRIC_*'],
'Imagick::compareImageLayers' => ['Imagick', 'method'=>'Imagick::LAYERMETHOD_*'],
'Imagick::compareImages' => ['array{Imagick,float}', 'compare'=>'imagick', 'metric'=>'Imagick::METRIC_*'],
'Imagick::compareImages' => ['list{Imagick,float}', 'compare'=>'imagick', 'metric'=>'Imagick::METRIC_*'],
'Imagick::compositeImage' => ['bool', 'composite_object'=>'imagick', 'composite'=>'Imagick::COMPOSITE_*', 'x'=>'int', 'y'=>'int', 'channel='=>'Imagick::CHANNEL_*'],
'Imagick::compositeImageGravity' => ['bool', 'imagick'=>'Imagick', 'COMPOSITE_CONSTANT'=>'int', 'GRAVITY_CONSTANT'=>'int'],
'Imagick::contrastImage' => ['bool', 'sharpen'=>'bool'],
Expand Down Expand Up @@ -9543,7 +9543,7 @@
'Redis::geoadd' => ['__benevolent<Redis|int|false>', 'key'=>'string', 'lng'=>'float', 'lat'=>'float', 'member'=>'string', '...other_triples_and_options='=>'mixed'],
'Redis::geodist' => ['__benevolent<Redis|float|false>', 'key'=>'string', 'member'=>'string', '...other_members='=>'string'],
'Redis::geohash' => ['__benevolent<Redis|array<int,string>|false>', 'key'=>'string', 'member'=>'string', '...other_members='=>'string'],
'Redis::geopos' => ['__benevolent<Redis|array<int,array{0:string,1:string}>|false>', 'key'=>'string', 'member'=>'string', '...other_members'=>'string'],
'Redis::geopos' => ['__benevolent<Redis|array<int,list{string,string}>|false>', 'key'=>'string', 'member'=>'string', '...other_members'=>'string'],
'Redis::georadius' => ['__benevolent<Redis|array<int,mixed>>', 'key'=>'string', 'lng'=>'float', 'lat'=>'float', 'radius'=>'float', 'unit'=>'string', 'options='=>'array<string,mixed>'],
'Redis::georadiusbymember' => ['__benevolent<Redis|array<int,mixed>>', 'key'=>'string', 'lng'=>'float', 'lat'=>'float', 'radius'=>'float', 'unit'=>'string', 'options='=>'array<string,mixed>'],
'Redis::georadiusbymember_ro' => ['__benevolent<Redis|array<int,mixed>>', 'key'=>'string', 'lng'=>'float', 'lat'=>'float', 'radius'=>'float', 'unit'=>'string', 'options='=>'array<string,mixed>'],
Expand All @@ -9567,7 +9567,7 @@
'Redis::getReadTimeout' => ['float'],
'Redis::getset' => ['__benevolent<Redis|string|false>', 'key'=>'string', 'value'=>'mixed'],
'Redis::getTimeout' => ['float|false'],
'Redis::getTransferredBytes' => ['array<int,array{0:int,1:int}>'],
'Redis::getTransferredBytes' => ['array<int,list{int,int}>'],
'Redis::hDel' => ['__benevolent<Redis|int|false>', 'key'=>'string', 'field'=>'string', '...other_fields='=>'string'],
'Redis::hExists' => ['__benevolent<Redis|bool>', 'key'=>'string', 'field'=>'string'],
'Redis::hGet' => ['__benevolent<Redis|string|false>', 'key'=>'string', 'member'=>'string'],
Expand Down Expand Up @@ -9693,7 +9693,7 @@
'Redis::sUnionStore' => ['__benevolent<Redis|int|false>', 'dst'=>'string', 'key'=>'string', '...other_keys='=>'string'],
'Redis::sunsubscribe' => ['__benevolent<Redis|string[]|false>', 'channels'=>'string[]'],
'Redis::swapdb' => ['__benevolent<Redis|bool>', 'src'=>'int', 'dst'=>'int'],
'Redis::time' => ['__benevolent<Redis|array{0:int,1:int}>'],
'Redis::time' => ['__benevolent<Redis|list{int,int}>'],
'Redis::ttl' => ['__benevolent<Redis|-2|-1|int|false>', 'key'=>'string'],
'Redis::type' => ['__benevolent<Redis|int|false>', 'key'=>'string'],
'Redis::unlink' => ['__benevolent<Redis|0|positive-int|false>', 'key'=>'string[]|string', '...other_keys'=>'string'],
Expand Down Expand Up @@ -11575,7 +11575,7 @@
'SplFileObject::fflush' => ['bool'],
'SplFileObject::fgetc' => ['string|false'],
// Do not believe https://www.php.net/manual/en/splfileobject.fgetcsv#refsect1-splfileobject.fgetcsv-returnvalues
'SplFileObject::fgetcsv' => ['list<string>|array{0: null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'SplFileObject::fgetcsv' => ['list<string>|list{null}|false|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'SplFileObject::fgets' => ['string'],
'SplFileObject::fgetss' => ['string|false', 'allowable_tags='=>'string'],
'SplFileObject::flock' => ['bool', 'operation'=>'int-mask<LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB>', '&w_wouldblock='=>'0|1'],
Expand Down Expand Up @@ -12602,7 +12602,7 @@
'timezone_transitions_get' => ['list<array{ts: int, time: string, offset: int, isdst: bool, abbr: string}>|false', 'object'=>'DateTimeZone', 'timestamp_begin='=>'int', 'timestamp_end='=>'int'],
'timezone_version_get' => ['string'],
'tmpfile' => ['__benevolent<resource|false>'],
'token_get_all' => ['list<string|array{0:int,1:string,2:int}>', 'source'=>'string', 'flags='=>'int'],
'token_get_all' => ['list<string|list{int,string,int}>', 'source'=>'string', 'flags='=>'int'],
'token_name' => ['non-falsy-string', 'type'=>'int'],
'TokyoTyrant::__construct' => ['void', 'host='=>'string', 'port='=>'int', 'options='=>'array'],
'TokyoTyrant::add' => ['int|float', 'key'=>'string', 'increment'=>'float', 'type='=>'int'],
Expand Down
2 changes: 1 addition & 1 deletion resources/functionMap_php80delta.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'error_log' => ['bool', 'message'=>'string', 'message_type='=>'0|1|3|4', 'destination='=>'string', 'extra_headers='=>'string'],
'explode' => ['list<string>', 'separator'=>'non-empty-string', 'str'=>'string', 'limit='=>'int'],
'fdiv' => ['float', 'dividend'=>'float', 'divisor'=>'float'],
'fgetcsv' => ['list<string>|array{0: null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'fgetcsv' => ['list<string>|list{null}|false', 'fp'=>'resource', 'length='=>'0|positive-int|null', 'delimiter='=>'string', 'enclosure='=>'string', 'escape='=>'string'],
'filter_input' => ['mixed', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'variable_name'=>'string', 'filter='=>'int', 'options='=>'array|int'],
'filter_input_array' => ['array|false|null', 'type'=>'INPUT_GET|INPUT_POST|INPUT_COOKIE|INPUT_SERVER|INPUT_ENV', 'definition='=>'int|array', 'add_empty='=>'bool'],
'floor' => ['float', 'number'=>'float'],
Expand Down
19 changes: 15 additions & 4 deletions src/PhpDoc/TypeNodeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,21 @@ function (CallableTypeParameterNode $parameterNode) use ($nameScope, &$isVariadi

private function resolveArrayShapeNode(ArrayShapeNode $typeNode, NameScope $nameScope): Type
{
$isListShape = in_array($typeNode->kind, [
ArrayShapeNode::KIND_LIST,
ArrayShapeNode::KIND_NON_EMPTY_LIST,
], true);

$builder = ConstantArrayTypeBuilder::createEmpty();
if (!$isListShape) {
foreach ($typeNode->items as $itemNode) {
if ($itemNode->keyName !== null) {
$builder = ConstantArrayTypeBuilder::createEmptyIndeterminate();
break;
}
}
}

if (count($typeNode->items) > ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT) {
$builder->degradeToGeneralArray(true);
}
Expand All @@ -1062,10 +1076,7 @@ private function resolveArrayShapeNode(ArrayShapeNode $typeNode, NameScope $name
}

$arrayType = $builder->getArray();
if (in_array($typeNode->kind, [
ArrayShapeNode::KIND_LIST,
ArrayShapeNode::KIND_NON_EMPTY_LIST,
], true)) {
if ($isListShape) {
$arrayType = TypeCombinator::intersect($arrayType, new AccessoryArrayListType());
}

Expand Down
5 changes: 5 additions & 0 deletions src/Type/Constant/ConstantArrayTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public static function createEmpty(): self
return new self([], [], [0], [], TrinaryLogic::createYes());
}

public static function createEmptyIndeterminate(): self
{
return new self([], [], [0], [], TrinaryLogic::createMaybe());
}

public static function createFromConstantArray(ConstantArrayType $startArrayType): self
{
$builder = new self(
Expand Down
13 changes: 6 additions & 7 deletions tests/PHPStan/Analyser/nsrt/list-shapes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ class Foo
*/
public function bar($l1, $l2, $l3, $l4, $l5, $l6): void
{
// TODO: list{}
assertType('array{}', $l1);
assertType("array{'a'}", $l2);
assertType("array{'a'}", $l3);
assertType("array{'a', 'b'}", $l4);
assertType("array{0: 'a', 1?: 'b'}", $l5);
assertType("array{'a', 'b'}", $l6);
assertType('list{}', $l1);
assertType("list{'a'}", $l2);
assertType("list{'a'}", $l3);
assertType("list{'a', 'b'}", $l4);
assertType("list{0: 'a', 1?: 'b'}", $l5);
assertType("list{'a', 'b'}", $l6);
}
}
Loading