Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Type/BenevolentUnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BenevolentUnionType extends UnionType

/**
* @api
* @param Type[] $types
* @param list<Type> $types
*/
public function __construct(array $types, bool $normalized = false)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ConstantArrayType implements Type

/**
* @api
* @param array<int, ConstantIntegerType|ConstantStringType> $keyTypes
* @param list<ConstantIntegerType|ConstantStringType> $keyTypes
* @param array<int, Type> $valueTypes
* @param non-empty-list<int> $nextAutoIndexes
* @param int[] $optionalKeys
Expand Down Expand Up @@ -280,7 +280,7 @@ private function powerSet(array $in): array
}

/**
* @return array<int, ConstantIntegerType|ConstantStringType>
* @return list<ConstantIntegerType|ConstantStringType>
*/
public function getKeyTypes(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Type/Constant/ConstantArrayTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class ConstantArrayTypeBuilder
private bool $oversized = false;

/**
* @param array<int, Type> $keyTypes
* @param list<Type> $keyTypes
* @param array<int, Type> $valueTypes
* @param non-empty-list<int> $nextAutoIndexes
* @param array<int> $optionalKeys
Expand Down Expand Up @@ -308,7 +308,7 @@ public function getArray(): Type
}

if (!$this->degradeToGeneralArray) {
/** @var array<int, ConstantIntegerType|ConstantStringType> $keyTypes */
/** @var list<ConstantIntegerType|ConstantStringType> $keyTypes */
$keyTypes = $this->keyTypes;
return new ConstantArrayType($keyTypes, $this->valueTypes, $this->nextAutoIndexes, $this->optionalKeys, $this->isList);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Generic/TemplateBenevolentUnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
$this->default = $default;
}

/** @param Type[] $types */
/** @param list<Type> $types */
public function withTypes(array $types): self
{
return new self(
Expand Down
6 changes: 3 additions & 3 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class IntersectionType implements CompoundType

/**
* @api
* @param Type[] $types
* @param list<Type> $types
*/
public function __construct(private array $types)
{
Expand All @@ -85,15 +85,15 @@ public function __construct(private array $types)
}

/**
* @return Type[]
* @return list<Type>
*/
public function getTypes(): array
{
return $this->types;
}

/**
* @return Type[]
* @return list<Type>
*/
private function getSortedTypes(): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Type/OperatorTypeSpecifyingExtensionRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function callOperatorTypeSpecifyingExtensions(Expr\BinaryOp $expr, Type $
$operatorSigil = $expr->getOperatorSigil();
$operatorTypeSpecifyingExtensions = $this->getOperatorTypeSpecifyingExtensions($operatorSigil, $leftType, $rightType);

/** @var Type[] $extensionTypes */
/** @var list<Type> $extensionTypes */
$extensionTypes = [];

foreach ($operatorTypeSpecifyingExtensions as $extension) {
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Php/ArrayMapFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
}

/**
* @return AccessoryType[]
* @return list<AccessoryType>
*/
private function getAccessoryTypes(Type $arrayType, Type $valueType): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Php/MinMaxFunctionReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function processArrayType(string $functionName, Type $argType): Type
}

/**
* @param Type[] $types
* @param list<Type> $types
*/
private function processType(
string $functionName,
Expand Down
12 changes: 6 additions & 6 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@

if ($tempTypes === []) {
if ($benevolentUnionObject instanceof TemplateBenevolentUnionType) {
return $benevolentUnionObject->withTypes($types);
return $benevolentUnionObject->withTypes(array_values($types));
}

return new BenevolentUnionType($types, true);
return new BenevolentUnionType(array_values($types), true);
}
}

return new UnionType($types, true);
return new UnionType(array_values($types), true);
}
Comment on lines 382 to 392
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might phpdoc-cast this parameter instead of doing a runtime array_values to reduce overhead


/**
Expand Down Expand Up @@ -546,7 +546,7 @@
}

/**
* @return array<Type>
* @return list<Type>
*/
private static function getAccessoryCaseStringTypes(Type $type): array
{
Expand Down Expand Up @@ -686,7 +686,7 @@

/**
* @param Type[] $arrayTypes
* @return Type[]
* @return list<Type>
*/
private static function processArrayAccessoryTypes(array $arrayTypes): array
{
Expand Down Expand Up @@ -1098,7 +1098,7 @@
unset($arraysToProcess[$i]);
continue 2;
}
}

Check failure on line 1101 in src/Type/TypeCombinator.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest, 0)

Parameter #1 $array (non-empty-list<PHPStan\Type\Type>) of array_values is already a list, call has no effect.

Check failure on line 1101 in src/Type/TypeCombinator.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest, 0)

Parameter #1 $array (non-empty-list<PHPStan\Type\Type>) of array_values is already a list, call has no effect.
}

return array_merge($newArrays, $arraysToProcess);
Expand Down Expand Up @@ -1473,7 +1473,7 @@
return $types[0];
}

return new IntersectionType($types);
return new IntersectionType(array_values($types));
}

public static function removeFalsey(Type $type): Type
Expand Down
2 changes: 1 addition & 1 deletion src/Type/TypeUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static function getHasPropertyTypes(Type $type): array
}

/**
* @return AccessoryType[]
* @return list<AccessoryType>
*/
public static function getAccessoryTypes(Type $type): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UnionType implements CompoundType

/**
* @api
* @param Type[] $types
* @param list<Type> $types
*/
public function __construct(private array $types, private bool $normalized = false)
{
Expand All @@ -90,7 +90,7 @@ public function __construct(private array $types, private bool $normalized = fal
}

/**
* @return Type[]
* @return list<Type>
*/
public function getTypes(): array
{
Expand Down Expand Up @@ -126,7 +126,7 @@ public function isNormalized(): bool
}

/**
* @return Type[]
* @return list<Type>
*/
protected function getSortedTypes(): array
{
Expand Down
5 changes: 3 additions & 2 deletions src/Type/UnionTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ final class UnionTypeHelper
{

/**
* @param Type[] $types
* @return Type[]
* @template T of Type
* @param list<T> $types
* @return list<T>
*/
public static function sortTypes(array $types): array
{
Expand Down
8 changes: 4 additions & 4 deletions tests/PHPStan/Type/TypeCombinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2805,7 +2805,7 @@ public static function dataUnion(): iterable
}

/**
* @param Type[] $types
* @param list<Type> $types
* @param class-string<Type> $expectedTypeClass
*/
#[DataProvider('dataUnion')]
Expand Down Expand Up @@ -2861,7 +2861,7 @@ public function testUnion(
}

/**
* @param Type[] $types
* @param list<Type> $types
* @param class-string<Type> $expectedTypeClass
*/
#[DataProvider('dataUnion')]
Expand Down Expand Up @@ -4760,7 +4760,7 @@ public static function dataIntersect(): iterable
}

/**
* @param Type[] $types
* @param list<Type> $types
* @param class-string<Type> $expectedTypeClass
*/
#[DataProvider('dataIntersect')]
Expand Down Expand Up @@ -4803,7 +4803,7 @@ public function testIntersect(
}

/**
* @param Type[] $types
* @param list<Type> $types
* @param class-string<Type> $expectedTypeClass
*/
#[DataProvider('dataIntersect')]
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Type/UnionTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ public function testSorting(): void
}

/**
* @param Type[] $types
* @param list<Type> $types
* @param list<string> $expectedDescriptions
*/
#[DataProvider('dataGetConstantArrays')]
Expand Down
Loading