diff --git a/src/Type/ObjectShapeType.php b/src/Type/ObjectShapeType.php index 8b32331b36..3d3b6140da 100644 --- a/src/Type/ObjectShapeType.php +++ b/src/Type/ObjectShapeType.php @@ -95,7 +95,7 @@ public function hasProperty(string $propertyName): TrinaryLogic return TrinaryLogic::createNo(); } - if (in_array($propertyName, $this->optionalProperties, true)) { + if ($this->isOptionalProperty($propertyName)) { return TrinaryLogic::createMaybe(); } @@ -122,6 +122,11 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember ); } + public function isOptionalProperty(string $property): bool + { + return in_array($property, $this->optionalProperties, true); + } + public function accepts(Type $type, bool $strictTypes): AcceptsResult { if ($type instanceof CompoundType) { @@ -156,14 +161,14 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult ], ); if ($hasProperty->no()) { - if (in_array($propertyName, $this->optionalProperties, true)) { + if ($this->isOptionalProperty($propertyName)) { continue; } $result = $result->and($hasProperty); continue; } if ($hasProperty->maybe()) { - if (!in_array($propertyName, $this->optionalProperties, true)) { + if (!$this->isOptionalProperty($propertyName)) { $result = $result->and($hasProperty); continue; @@ -262,14 +267,14 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult foreach ($this->properties as $propertyName => $propertyType) { $hasProperty = new IsSuperTypeOfResult($type->hasProperty((string) $propertyName), []); if ($hasProperty->no()) { - if (in_array($propertyName, $this->optionalProperties, true)) { + if ($this->isOptionalProperty($propertyName)) { continue; } $result = $result->and($hasProperty); continue; } if ($hasProperty->maybe()) { - if (!in_array($propertyName, $this->optionalProperties, true)) { + if (!$this->isOptionalProperty($propertyName)) { $result = $result->and($hasProperty); continue; } @@ -339,7 +344,7 @@ public function equals(Type $type): bool } foreach ($this->optionalProperties as $name) { - if (in_array($name, $type->optionalProperties, true)) { + if ($type->isOptionalProperty($name)) { continue; } @@ -526,7 +531,7 @@ public function toPhpDocNode(): TypeNode } $items[] = new ObjectShapeItemNode( $keyNode, - in_array($name, $this->optionalProperties, true), + $this->isOptionalProperty($name), $type->toPhpDocNode(), ); }