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
27 changes: 18 additions & 9 deletions src/Type/Accessory/AccessoryArrayListType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPStan\Type\ErrorType;
use PHPStan\Type\IntegerRangeType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\MixedType;
use PHPStan\Type\Traits\MaybeCallableTypeTrait;
use PHPStan\Type\Traits\NonGeneralizableTypeTrait;
Expand Down Expand Up @@ -93,28 +94,36 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
}

public function isSuperTypeOf(Type $type): TrinaryLogic
{
return $this->isSuperTypeOfWithReason($type)->result;
}

public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
{
if ($this->equals($type)) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

if ($type instanceof CompoundType) {
return $type->isSubTypeOf($this);
return $type->isSubTypeOfWithReason($this);
}

return $type->isArray()
->and($type->isList());
return new IsSuperTypeOfResult($type->isArray()->and($type->isList()), []);
}

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
return $this->isSubTypeOfWithReason($otherType)->result;
}

public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
return $otherType->isSuperTypeOf($this);
return $otherType->isSuperTypeOfWithReason($this);
}

return $otherType->isArray()
->and($otherType->isList())
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isList()), []))
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
}

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
Expand All @@ -124,7 +133,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog

public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult
{
return new AcceptsResult($this->isSubTypeOf($acceptingType), []);
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
}

public function equals(Type $type): bool
Expand Down
25 changes: 18 additions & 7 deletions src/Type/Accessory/AccessoryLiteralStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
Expand Down Expand Up @@ -85,26 +86,36 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
}

public function isSuperTypeOf(Type $type): TrinaryLogic
{
return $this->isSuperTypeOfWithReason($type)->result;
}

public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
{
if ($type instanceof CompoundType) {
return $type->isSubTypeOf($this);
return $type->isSubTypeOfWithReason($this);
}

if ($this->equals($type)) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

return $type->isLiteralString();
return new IsSuperTypeOfResult($type->isLiteralString(), []);
}

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
return $this->isSubTypeOfWithReason($otherType)->result;
}

public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
return $otherType->isSuperTypeOf($this);
return $otherType->isSuperTypeOfWithReason($this);
}

return $otherType->isLiteralString()
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
return (new IsSuperTypeOfResult($otherType->isLiteralString(), []))
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
}

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
Expand All @@ -114,7 +125,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog

public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult
{
return new AcceptsResult($this->isSubTypeOf($acceptingType), []);
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
}

public function equals(Type $type): bool
Expand Down
25 changes: 18 additions & 7 deletions src/Type/Accessory/AccessoryLowercaseStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\Traits\MaybeCallableTypeTrait;
Expand Down Expand Up @@ -81,26 +82,36 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
}

public function isSuperTypeOf(Type $type): TrinaryLogic
{
return $this->isSuperTypeOfWithReason($type)->result;
}

public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
{
if ($type instanceof CompoundType) {
return $type->isSubTypeOf($this);
return $type->isSubTypeOfWithReason($this);
}

if ($this->equals($type)) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

return $type->isLowercaseString();
return new IsSuperTypeOfResult($type->isLowercaseString(), []);
}

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
return $this->isSubTypeOfWithReason($otherType)->result;
}

public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
return $otherType->isSuperTypeOf($this);
return $otherType->isSuperTypeOfWithReason($this);
}

return $otherType->isLowercaseString()
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
return (new IsSuperTypeOfResult($otherType->isLowercaseString(), []))
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
}

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
Expand All @@ -110,7 +121,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog

public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult
{
return new AcceptsResult($this->isSubTypeOf($acceptingType), []);
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
}

public function equals(Type $type): bool
Expand Down
27 changes: 19 additions & 8 deletions src/Type/Accessory/AccessoryNonEmptyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\Traits\MaybeCallableTypeTrait;
Expand Down Expand Up @@ -83,30 +84,40 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
}

public function isSuperTypeOf(Type $type): TrinaryLogic
{
return $this->isSuperTypeOfWithReason($type)->result;
}

public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
{
if ($type instanceof CompoundType) {
return $type->isSubTypeOf($this);
return $type->isSubTypeOfWithReason($this);
}

if ($this->equals($type)) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

if ($type->isNonFalsyString()->yes()) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

return $type->isNonEmptyString();
return new IsSuperTypeOfResult($type->isNonEmptyString(), []);
}

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
return $this->isSubTypeOfWithReason($otherType)->result;
}

public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
return $otherType->isSuperTypeOf($this);
return $otherType->isSuperTypeOfWithReason($this);
}

return $otherType->isNonEmptyString()
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
return (new IsSuperTypeOfResult($otherType->isNonEmptyString(), []))
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
}

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
Expand All @@ -116,7 +127,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog

public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult
{
return new AcceptsResult($this->isSubTypeOf($acceptingType), []);
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
}

public function equals(Type $type): bool
Expand Down
27 changes: 19 additions & 8 deletions src/Type/Accessory/AccessoryNonFalsyStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\StringType;
use PHPStan\Type\Traits\MaybeCallableTypeTrait;
Expand Down Expand Up @@ -83,30 +84,40 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
}

public function isSuperTypeOf(Type $type): TrinaryLogic
{
return $this->isSuperTypeOfWithReason($type)->result;
}

public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
{
if ($type instanceof CompoundType) {
return $type->isSubTypeOf($this);
return $type->isSubTypeOfWithReason($this);
}

if ($this->equals($type)) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

return $type->isNonFalsyString();
return new IsSuperTypeOfResult($type->isNonFalsyString(), []);
}

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
return $this->isSubTypeOfWithReason($otherType)->result;
}

public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
return $otherType->isSuperTypeOf($this);
return $otherType->isSuperTypeOfWithReason($this);
}

if ($otherType instanceof AccessoryNonEmptyStringType) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

return $otherType->isNonFalsyString()
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
return (new IsSuperTypeOfResult($otherType->isNonFalsyString(), []))
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
}

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
Expand All @@ -116,7 +127,7 @@ public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLog

public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes): AcceptsResult
{
return new AcceptsResult($this->isSubTypeOf($acceptingType), []);
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
}

public function equals(Type $type): bool
Expand Down
25 changes: 18 additions & 7 deletions src/Type/Accessory/AccessoryNumericStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Type\GeneralizePrecision;
use PHPStan\Type\IntegerType;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\IsSuperTypeOfResult;
use PHPStan\Type\StringType;
use PHPStan\Type\Traits\NonArrayTypeTrait;
use PHPStan\Type\Traits\NonCallableTypeTrait;
Expand Down Expand Up @@ -82,26 +83,36 @@ public function acceptsWithReason(Type $type, bool $strictTypes): AcceptsResult
}

public function isSuperTypeOf(Type $type): TrinaryLogic
{
return $this->isSuperTypeOfWithReason($type)->result;
}

public function isSuperTypeOfWithReason(Type $type): IsSuperTypeOfResult
{
if ($type instanceof CompoundType) {
return $type->isSubTypeOf($this);
return $type->isSubTypeOfWithReason($this);
}

if ($this->equals($type)) {
return TrinaryLogic::createYes();
return IsSuperTypeOfResult::createYes();
}

return $type->isNumericString();
return new IsSuperTypeOfResult($type->isNumericString(), []);
}

public function isSubTypeOf(Type $otherType): TrinaryLogic
{
return $this->isSubTypeOfWithReason($otherType)->result;
}

public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
{
if ($otherType instanceof UnionType || $otherType instanceof IntersectionType) {
return $otherType->isSuperTypeOf($this);
return $otherType->isSuperTypeOfWithReason($this);
}

return $otherType->isNumericString()
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe());
return (new IsSuperTypeOfResult($otherType->isNumericString(), []))
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
}

public function isAcceptedBy(Type $acceptingType, bool $strictTypes): TrinaryLogic
Expand All @@ -119,7 +130,7 @@ public function isAcceptedWithReasonBy(Type $acceptingType, bool $strictTypes):
return AcceptsResult::createYes();
}

return new AcceptsResult($this->isSubTypeOf($acceptingType), []);
return $this->isSubTypeOfWithReason($acceptingType)->toAcceptsResult();
}

public function equals(Type $type): bool
Expand Down
Loading
Loading