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
6 changes: 6 additions & 0 deletions src/Type/Accessory/HasMethodType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\TrinaryLogic;
use PHPStan\Type\AcceptsResult;
use PHPStan\Type\CompoundType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
Expand Down Expand Up @@ -166,6 +167,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
6 changes: 6 additions & 0 deletions src/Type/Accessory/HasOffsetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Type\CompoundType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntersectionType;
Expand Down Expand Up @@ -412,6 +413,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
6 changes: 6 additions & 0 deletions src/Type/Accessory/HasOffsetValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\ConstantScalarType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntegerType;
Expand Down Expand Up @@ -476,6 +477,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function traverse(callable $cb): Type
{
$newValueType = $cb($this->valueType);
Expand Down
6 changes: 6 additions & 0 deletions src/Type/Accessory/HasPropertyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\TrinaryLogic;
use PHPStan\Type\AcceptsResult;
use PHPStan\Type\CompoundType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
Expand Down Expand Up @@ -149,6 +150,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
6 changes: 6 additions & 0 deletions src/Type/CallableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Accessory\AccessoryNonEmptyStringType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Generic\TemplateTypeMap;
Expand Down Expand Up @@ -645,6 +646,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function isCommonCallable(): bool
{
return $this->isCommonCallable;
Expand Down
6 changes: 6 additions & 0 deletions src/Type/ClosureType.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Generic\TemplateTypeMap;
Expand Down Expand Up @@ -423,6 +424,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function isCommonCallable(): bool
{
return $this->isCommonCallable;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Enum/EnumCaseObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ public function getEnumCases(): array
return [$this];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return $this;
}

public function toPhpDocNode(): TypeNode
{
return new ConstTypeNode(
Expand Down
20 changes: 20 additions & 0 deletions src/Type/IntersectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
Expand Down Expand Up @@ -1032,6 +1033,25 @@ public function getEnumCases(): array
return array_values(array_intersect_key(...$compare));
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
$singleCase = null;
foreach ($this->types as $type) {
$caseObject = $type->getEnumCaseObject();
if ($caseObject === null) {
continue;
}

if ($singleCase !== null) {
return null;
}

$singleCase = $caseObject;
}

return $singleCase;
}

public function isCallable(): TrinaryLogic
{
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isCallable());
Expand Down
6 changes: 6 additions & 0 deletions src/Type/IterableType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\TemplateMixedType;
use PHPStan\Type\Generic\TemplateTypeMap;
Expand Down Expand Up @@ -421,6 +422,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
{
if ($receivedType instanceof UnionType || $receivedType instanceof IntersectionType) {
Expand Down
6 changes: 6 additions & 0 deletions src/Type/MixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PHPStan\Type\Constant\ConstantFloatType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateMixedType;
use PHPStan\Type\Generic\TemplateType;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
Expand Down Expand Up @@ -320,6 +321,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
{
return [new TrivialParametersAcceptor()];
Expand Down
6 changes: 6 additions & 0 deletions src/Type/NeverType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
use PHPStan\Type\Traits\NonGenericTypeTrait;
use PHPStan\Type\Traits\NonRemoveableTypeTrait;
Expand Down Expand Up @@ -558,6 +559,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function exponentiate(Type $exponent): Type
{
return $this;
Expand Down
6 changes: 6 additions & 0 deletions src/Type/NonexistentParentClassType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Traits\NonArrayTypeTrait;
use PHPStan\Type\Traits\NonCallableTypeTrait;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
Expand Down Expand Up @@ -212,6 +213,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function exponentiate(Type $exponent): Type
{
return new ErrorType();
Expand Down
6 changes: 6 additions & 0 deletions src/Type/ObjectShapeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use PHPStan\Type\Accessory\HasPropertyType;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
Expand Down Expand Up @@ -463,6 +464,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function traverse(callable $cb): Type
{
$properties = [];
Expand Down
11 changes: 11 additions & 0 deletions src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,17 @@ public function getEnumCases(): array
return self::$enumCases[$cacheKey] = $cases;
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
$cases = $this->getEnumCases();

if (count($cases) === 1) {
return $cases[0];
}

return null;
}

public function isCallable(): TrinaryLogic
{
$parametersAcceptors = RecursionGuard::run($this, fn () => $this->findCallableParametersAcceptors());
Expand Down
6 changes: 6 additions & 0 deletions src/Type/ObjectWithoutClassType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
use PHPStan\Type\Traits\NonGenericTypeTrait;
use PHPStan\Type\Traits\ObjectTypeTrait;
Expand Down Expand Up @@ -130,6 +131,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function subtract(Type $type): Type
{
if ($type instanceof self) {
Expand Down
6 changes: 6 additions & 0 deletions src/Type/StaticType.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPStan\Reflection\Type\UnresolvedMethodPrototypeReflection;
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\GenericObjectType;
use PHPStan\Type\Generic\TemplateTypeHelper;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
Expand Down Expand Up @@ -539,6 +540,11 @@ public function getEnumCases(): array
return $this->getStaticObjectType()->getEnumCases();
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return $this->getStaticObjectType()->getEnumCaseObject();
}

public function isArray(): TrinaryLogic
{
return $this->getStaticObjectType()->isArray();
Expand Down
6 changes: 6 additions & 0 deletions src/Type/StrictMixedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateMixedType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\Generic\TemplateTypeVariance;
Expand Down Expand Up @@ -445,6 +446,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
6 changes: 6 additions & 0 deletions src/Type/Traits/LateResolvableTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use PHPStan\Type\AcceptsResult;
use PHPStan\Type\BooleanType;
use PHPStan\Type\CompoundType;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\Generic\TemplateTypeMap;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\LateResolvableType;
Expand Down Expand Up @@ -358,6 +359,11 @@ public function getEnumCases(): array
return $this->resolve()->getEnumCases();
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return $this->resolve()->getEnumCaseObject();
}

public function getCallableParametersAcceptors(ClassMemberAccessAnswerer $scope): array
{
return $this->resolve()->getCallableParametersAcceptors($scope);
Expand Down
6 changes: 6 additions & 0 deletions src/Type/Traits/NonObjectTypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPStan\Reflection\Type\UnresolvedPropertyPrototypeReflection;
use PHPStan\ShouldNotHappenException;
use PHPStan\TrinaryLogic;
use PHPStan\Type\Enum\EnumCaseObjectType;
use PHPStan\Type\ErrorType;
use PHPStan\Type\Type;

Expand Down Expand Up @@ -126,6 +127,11 @@ public function getEnumCases(): array
return [];
}

public function getEnumCaseObject(): ?EnumCaseObjectType
{
return null;
}

public function getTemplateType(string $ancestorClassName, string $templateTypeName): Type
{
return new ErrorType();
Expand Down
2 changes: 2 additions & 0 deletions src/Type/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ public function spliceArray(Type $offsetType, Type $lengthType, Type $replacemen
*/
public function getEnumCases(): array;

public function getEnumCaseObject(): ?EnumCaseObjectType;

/**
* Returns a list of finite values.
*
Expand Down
Loading
Loading