Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c131109

Browse files
committed
feat: add isOptionalProperty method to ObjectShapeType
1 parent 774f1ab commit c131109

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

‎src/Type/ObjectShapeType.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function hasProperty(string $propertyName): TrinaryLogic
9595
return TrinaryLogic::createNo();
9696
}
9797

98-
if (in_array($propertyName, $this->optionalProperties, true)) {
98+
if ($this->isOptionalProperty($propertyName)) {
9999
return TrinaryLogic::createMaybe();
100100
}
101101

@@ -122,6 +122,11 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
122122
);
123123
}
124124

125+
public function isOptionalProperty(string $property): bool
126+
{
127+
return in_array($property, $this->optionalProperties, true);
128+
}
129+
125130
public function accepts(Type $type, bool $strictTypes): AcceptsResult
126131
{
127132
if ($type instanceof CompoundType) {
@@ -156,14 +161,14 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
156161
],
157162
);
158163
if ($hasProperty->no()) {
159-
if (in_array($propertyName, $this->optionalProperties, true)) {
164+
if ($this->isOptionalProperty($propertyName)) {
160165
continue;
161166
}
162167
$result = $result->and($hasProperty);
163168
continue;
164169
}
165170
if ($hasProperty->maybe()) {
166-
if (!in_array($propertyName, $this->optionalProperties, true)) {
171+
if (!$this->isOptionalProperty($propertyName)) {
167172
$result = $result->and($hasProperty);
168173
continue;
169174

@@ -262,14 +267,14 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
262267
foreach ($this->properties as $propertyName => $propertyType) {
263268
$hasProperty = new IsSuperTypeOfResult($type->hasProperty((string) $propertyName), []);
264269
if ($hasProperty->no()) {
265-
if (in_array($propertyName, $this->optionalProperties, true)) {
270+
if ($this->isOptionalProperty($propertyName)) {
266271
continue;
267272
}
268273
$result = $result->and($hasProperty);
269274
continue;
270275
}
271276
if ($hasProperty->maybe()) {
272-
if (!in_array($propertyName, $this->optionalProperties, true)) {
277+
if (!$this->isOptionalProperty($propertyName)) {
273278
$result = $result->and($hasProperty);
274279
continue;
275280
}
@@ -339,7 +344,7 @@ public function equals(Type $type): bool
339344
}
340345

341346
foreach ($this->optionalProperties as $name) {
342-
if (in_array($name, $type->optionalProperties, true)) {
347+
if ($type->isOptionalProperty($name)) {
343348
continue;
344349
}
345350

@@ -526,7 +531,7 @@ public function toPhpDocNode(): TypeNode
526531
}
527532
$items[] = new ObjectShapeItemNode(
528533
$keyNode,
529-
in_array($name, $this->optionalProperties, true),
534+
$this->isOptionalProperty($name),
530535
$type->toPhpDocNode(),
531536
);
532537
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /