Skip to content

Commit 479ff62

Browse files
authored
Faster IsSuperTypeOfResult creation (#5042)
1 parent b538b8f commit 479ff62

14 files changed

+59
-35
lines changed

src/Type/Accessory/AccessoryArrayListType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
110110
return $otherType->isSuperTypeOf($this);
111111
}
112112

113-
return (new IsSuperTypeOfResult($otherType->isArray()->and($otherType->isList()), []))
114-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
113+
return new IsSuperTypeOfResult(
114+
$otherType->isArray()->and($otherType->isList())->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
115+
[],
116+
);
115117
}
116118

117119
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/AccessoryLiteralStringType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
106106
return $otherType->isSuperTypeOf($this);
107107
}
108108

109-
return (new IsSuperTypeOfResult($otherType->isLiteralString(), []))
110-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
109+
return new IsSuperTypeOfResult(
110+
$otherType->isLiteralString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
111+
[],
112+
);
111113
}
112114

113115
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/AccessoryLowercaseStringType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
103103
return $otherType->isSuperTypeOf($this);
104104
}
105105

106-
return (new IsSuperTypeOfResult($otherType->isLowercaseString(), []))
107-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
106+
return new IsSuperTypeOfResult(
107+
$otherType->isLowercaseString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
108+
[],
109+
);
108110
}
109111

110112
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/AccessoryNonEmptyStringType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
108108
return $otherType->isSuperTypeOf($this);
109109
}
110110

111-
return (new IsSuperTypeOfResult($otherType->isNonEmptyString(), []))
112-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
111+
return new IsSuperTypeOfResult(
112+
$otherType->isNonEmptyString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
113+
[],
114+
);
113115
}
114116

115117
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/AccessoryNonFalsyStringType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
110110
return IsSuperTypeOfResult::createYes();
111111
}
112112

113-
return (new IsSuperTypeOfResult($otherType->isNonFalsyString(), []))
114-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
113+
return new IsSuperTypeOfResult(
114+
$otherType->isNonFalsyString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
115+
[],
116+
);
115117
}
116118

117119
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/AccessoryNumericStringType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
103103
return $otherType->isSuperTypeOf($this);
104104
}
105105

106-
return (new IsSuperTypeOfResult($otherType->isNumericString(), []))
107-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
106+
return new IsSuperTypeOfResult(
107+
$otherType->isNumericString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
108+
[],
109+
);
108110
}
109111

110112
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/AccessoryUppercaseStringType.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
103103
return $otherType->isSuperTypeOf($this);
104104
}
105105

106-
return (new IsSuperTypeOfResult($otherType->isUppercaseString(), []))
107-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
106+
return new IsSuperTypeOfResult(
107+
$otherType->isUppercaseString()->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
108+
[],
109+
);
108110
}
109111

110112
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/HasMethodType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
100100
}
101101

102102
if ($otherType instanceof self) {
103-
$limit = IsSuperTypeOfResult::createYes();
103+
$limit = TrinaryLogic::createYes();
104104
} else {
105-
$limit = IsSuperTypeOfResult::createMaybe();
105+
$limit = TrinaryLogic::createMaybe();
106106
}
107107

108-
return $limit->and(new IsSuperTypeOfResult($otherType->hasMethod($this->methodName), []));
108+
return new IsSuperTypeOfResult($limit->and($otherType->hasMethod($this->methodName)), []);
109109
}
110110

111111
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/HasOffsetType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
101101
return $otherType->isSuperTypeOf($this);
102102
}
103103

104-
$result = new IsSuperTypeOfResult($otherType->isOffsetAccessible()->and($otherType->hasOffsetValueType($this->offsetType)), []);
105-
106-
return $result
107-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
104+
return new IsSuperTypeOfResult(
105+
$otherType->isOffsetAccessible()->and($otherType->hasOffsetValueType($this->offsetType))->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
106+
[],
107+
);
108108
}
109109

110110
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

src/Type/Accessory/HasOffsetValueType.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,15 @@ public function isSubTypeOf(Type $otherType): IsSuperTypeOfResult
116116
return $otherType->isSuperTypeOf($this);
117117
}
118118

119-
$result = new IsSuperTypeOfResult($otherType->isOffsetAccessible()->and($otherType->hasOffsetValueType($this->offsetType)), []);
119+
$result = new IsSuperTypeOfResult(
120+
$otherType->isOffsetAccessible()
121+
->and($otherType->hasOffsetValueType($this->offsetType))
122+
->and($otherType instanceof self ? TrinaryLogic::createYes() : TrinaryLogic::createMaybe()),
123+
[],
124+
);
120125

121126
return $result
122-
->and($otherType->getOffsetValueType($this->offsetType)->isSuperTypeOf($this->valueType))
123-
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
127+
->and($otherType->getOffsetValueType($this->offsetType)->isSuperTypeOf($this->valueType));
124128
}
125129

126130
public function isAcceptedBy(Type $acceptingType, bool $strictTypes): AcceptsResult

0 commit comments

Comments
 (0)