@@ -95,7 +95,7 @@ public function hasProperty(string $propertyName): TrinaryLogic
95
95
return TrinaryLogic::createNo ();
96
96
}
97
97
98
- if (in_array ( $ propertyName , $ this ->optionalProperties , true )) {
98
+ if ($ this ->isOptionalProperty ( $ propertyName )) {
99
99
return TrinaryLogic::createMaybe ();
100
100
}
101
101
@@ -122,6 +122,11 @@ public function getUnresolvedPropertyPrototype(string $propertyName, ClassMember
122
122
);
123
123
}
124
124
125
+ public function isOptionalProperty (string $ property ): bool
126
+ {
127
+ return in_array ($ property , $ this ->optionalProperties , true );
128
+ }
129
+
125
130
public function accepts (Type $ type , bool $ strictTypes ): AcceptsResult
126
131
{
127
132
if ($ type instanceof CompoundType) {
@@ -156,14 +161,14 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
156
161
],
157
162
);
158
163
if ($ hasProperty ->no ()) {
159
- if (in_array ( $ propertyName , $ this ->optionalProperties , true )) {
164
+ if ($ this ->isOptionalProperty ( $ propertyName )) {
160
165
continue ;
161
166
}
162
167
$ result = $ result ->and ($ hasProperty );
163
168
continue ;
164
169
}
165
170
if ($ hasProperty ->maybe ()) {
166
- if (!in_array ( $ propertyName , $ this ->optionalProperties , true )) {
171
+ if (!$ this ->isOptionalProperty ( $ propertyName )) {
167
172
$ result = $ result ->and ($ hasProperty );
168
173
continue ;
169
174
@@ -262,14 +267,14 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
262
267
foreach ($ this ->properties as $ propertyName => $ propertyType ) {
263
268
$ hasProperty = new IsSuperTypeOfResult ($ type ->hasProperty ((string ) $ propertyName ), []);
264
269
if ($ hasProperty ->no ()) {
265
- if (in_array ( $ propertyName , $ this ->optionalProperties , true )) {
270
+ if ($ this ->isOptionalProperty ( $ propertyName )) {
266
271
continue ;
267
272
}
268
273
$ result = $ result ->and ($ hasProperty );
269
274
continue ;
270
275
}
271
276
if ($ hasProperty ->maybe ()) {
272
- if (!in_array ( $ propertyName , $ this ->optionalProperties , true )) {
277
+ if (!$ this ->isOptionalProperty ( $ propertyName )) {
273
278
$ result = $ result ->and ($ hasProperty );
274
279
continue ;
275
280
}
@@ -339,7 +344,7 @@ public function equals(Type $type): bool
339
344
}
340
345
341
346
foreach ($ this ->optionalProperties as $ name ) {
342
- if (in_array ( $ name , $ type ->optionalProperties , true )) {
347
+ if ($ type ->isOptionalProperty ( $ name )) {
343
348
continue ;
344
349
}
345
350
@@ -526,7 +531,7 @@ public function toPhpDocNode(): TypeNode
526
531
}
527
532
$ items [] = new ObjectShapeItemNode (
528
533
$ keyNode ,
529
- in_array ( $ name , $ this ->optionalProperties , true ),
534
+ $ this ->isOptionalProperty ( $ name ),
530
535
$ type ->toPhpDocNode (),
531
536
);
532
537
}
0 commit comments