Skip to content

Commit

Permalink
Add Type::isScalar()
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Dec 28, 2022
1 parent a5b5090 commit 1e7b58a
Show file tree
Hide file tree
Showing 33 changed files with 251 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryArrayListType.php
Expand Up @@ -322,6 +322,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function toNumber(): Type
{
return new ErrorType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryLiteralStringType.php
Expand Up @@ -236,6 +236,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryNonEmptyStringType.php
Expand Up @@ -236,6 +236,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryNonFalsyStringType.php
Expand Up @@ -236,6 +236,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/AccessoryNumericStringType.php
Expand Up @@ -239,6 +239,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/HasOffsetType.php
Expand Up @@ -239,6 +239,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createMaybe();
}

public function getKeysArray(): Type
{
return new NonEmptyArrayType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/HasOffsetValueType.php
Expand Up @@ -290,6 +290,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createMaybe();
}

public function toNumber(): Type
{
return new ErrorType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/NonEmptyArrayType.php
Expand Up @@ -307,6 +307,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function toNumber(): Type
{
return new ErrorType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Accessory/OversizedArrayType.php
Expand Up @@ -306,6 +306,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function toNumber(): Type
{
return new ErrorType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/ArrayType.php
Expand Up @@ -327,6 +327,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function isOffsetAccessible(): TrinaryLogic
{
return TrinaryLogic::createYes();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/BooleanType.php
Expand Up @@ -113,6 +113,11 @@ public function isBoolean(): TrinaryLogic
return TrinaryLogic::createYes();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function tryRemove(Type $typeToRemove): ?Type
{
if ($typeToRemove instanceof ConstantBooleanType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/CallableType.php
Expand Up @@ -392,6 +392,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createMaybe();
}

public function isCommonCallable(): bool
{
return $this->isCommonCallable;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/ClosureType.php
Expand Up @@ -461,6 +461,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

/**
* @param mixed[] $properties
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Type/FloatType.php
Expand Up @@ -191,6 +191,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/IntegerType.php
Expand Up @@ -123,6 +123,11 @@ public function isInteger(): TrinaryLogic
return TrinaryLogic::createYes();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function tryRemove(Type $typeToRemove): ?Type
{
if ($typeToRemove instanceof IntegerRangeType || $typeToRemove instanceof ConstantIntegerType) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/IntersectionType.php
Expand Up @@ -534,6 +534,11 @@ public function isVoid(): TrinaryLogic
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isVoid());
}

public function isScalar(): TrinaryLogic
{
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isScalar());
}

public function isOffsetAccessible(): TrinaryLogic
{
return $this->intersectResults(static fn (Type $type): TrinaryLogic => $type->isOffsetAccessible());
Expand Down
5 changes: 5 additions & 0 deletions src/Type/IterableType.php
Expand Up @@ -330,6 +330,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
{
if ($receivedType instanceof UnionType || $receivedType instanceof IntersectionType) {
Expand Down
11 changes: 11 additions & 0 deletions src/Type/MixedType.php
Expand Up @@ -776,6 +776,17 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createMaybe();
}

public function isScalar(): TrinaryLogic
{
if ($this->subtractedType !== null) {
if ($this->subtractedType->isSuperTypeOf(new UnionType([new BooleanType(), new FloatType(), new IntegerType(), new StringType()]))->yes()) {
return TrinaryLogic::createNo();
}
}

return TrinaryLogic::createMaybe();
}

public function tryRemove(Type $typeToRemove): ?Type
{
if ($this->isSuperTypeOf($typeToRemove)->yes()) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/NeverType.php
Expand Up @@ -403,6 +403,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

/**
* @param mixed[] $properties
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Type/NonexistentParentClassType.php
Expand Up @@ -134,6 +134,11 @@ public function toArrayKey(): Type
return new ErrorType();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

/**
* @param mixed[] $properties
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Type/NullType.php
Expand Up @@ -247,6 +247,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function getSmallerType(): Type
{
return new NeverType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/ObjectType.php
Expand Up @@ -909,6 +909,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

private function isExtraOffsetAccessibleClass(): TrinaryLogic
{
$classReflection = $this->getClassReflection();
Expand Down
6 changes: 6 additions & 0 deletions src/Type/ResourceType.php
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Type;

use PHPStan\TrinaryLogic;
use PHPStan\Type\Constant\ConstantArrayType;
use PHPStan\Type\Constant\ConstantIntegerType;
use PHPStan\Type\Traits\NonArrayTypeTrait;
Expand Down Expand Up @@ -82,6 +83,11 @@ public function toArrayKey(): Type
return new ErrorType();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

/**
* @param mixed[] $properties
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Type/StaticType.php
Expand Up @@ -496,6 +496,11 @@ public function isVoid(): TrinaryLogic
return $this->getStaticObjectType()->isVoid();
}

public function isScalar(): TrinaryLogic
{
return $this->getStaticObjectType()->isScalar();
}

/**
* @return ParametersAcceptor[]
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Type/StrictMixedType.php
Expand Up @@ -222,6 +222,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function isOffsetAccessible(): TrinaryLogic
{
return TrinaryLogic::createNo();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/StringType.php
Expand Up @@ -209,6 +209,11 @@ public function isClassStringType(): TrinaryLogic
return TrinaryLogic::createMaybe();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createYes();
}

public function hasMethod(string $methodName): TrinaryLogic
{
if ($this->isClassStringType()->yes()) {
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Traits/LateResolvableTypeTrait.php
Expand Up @@ -380,6 +380,11 @@ public function isVoid(): TrinaryLogic
return $this->resolve()->isVoid();
}

public function isScalar(): TrinaryLogic
{
return $this->resolve()->isScalar();
}

public function getSmallerType(): Type
{
return $this->resolve()->getSmallerType();
Expand Down
5 changes: 5 additions & 0 deletions src/Type/Traits/ObjectTypeTrait.php
Expand Up @@ -171,6 +171,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createNo();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function toNumber(): Type
{
return new ErrorType();
Expand Down
2 changes: 2 additions & 0 deletions src/Type/Type.php
Expand Up @@ -171,6 +171,8 @@ public function isClassStringType(): TrinaryLogic;

public function isVoid(): TrinaryLogic;

public function isScalar(): TrinaryLogic;

public function getSmallerType(): Type;

public function getSmallerOrEqualType(): Type;
Expand Down
5 changes: 5 additions & 0 deletions src/Type/UnionType.php
Expand Up @@ -526,6 +526,11 @@ public function isVoid(): TrinaryLogic
return $this->unionResults(static fn (Type $type): TrinaryLogic => $type->isVoid());
}

public function isScalar(): TrinaryLogic
{
return $this->unionResults(static fn (Type $type): TrinaryLogic => $type->isScalar());
}

public function isOffsetAccessible(): TrinaryLogic
{
return $this->unionResults(static fn (Type $type): TrinaryLogic => $type->isOffsetAccessible());
Expand Down
5 changes: 5 additions & 0 deletions src/Type/VoidType.php
Expand Up @@ -169,6 +169,11 @@ public function isVoid(): TrinaryLogic
return TrinaryLogic::createYes();
}

public function isScalar(): TrinaryLogic
{
return TrinaryLogic::createNo();
}

public function traverse(callable $cb): Type
{
return $this;
Expand Down

0 comments on commit 1e7b58a

Please sign in to comment.