@@ -44,23 +44,23 @@ class ObjectShapeType implements Type
44
44
45
45
/**
46
46
* @api
47
- * @param array<string, Type> $properties
48
- * @param list<string> $optionalProperties
47
+ * @param array<int| string, Type> $properties
48
+ * @param list<int| string> $optionalProperties
49
49
*/
50
50
public function __construct (private array $ properties , private array $ optionalProperties )
51
51
{
52
52
}
53
53
54
54
/**
55
- * @return array<string, Type>
55
+ * @return array<int| string, Type>
56
56
*/
57
57
public function getProperties (): array
58
58
{
59
59
return $ this ->properties ;
60
60
}
61
61
62
62
/**
63
- * @return list<string>
63
+ * @return list<int| string>
64
64
*/
65
65
public function getOptionalProperties (): array
66
66
{
@@ -143,7 +143,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
143
143
$ result = AcceptsResult::createYes ();
144
144
$ scope = new OutOfClassScope ();
145
145
foreach ($ this ->properties as $ propertyName => $ propertyType ) {
146
- $ typeHasProperty = $ type ->hasProperty ($ propertyName );
146
+ $ typeHasProperty = $ type ->hasProperty (( string ) $ propertyName );
147
147
$ hasProperty = new AcceptsResult (
148
148
$ typeHasProperty ,
149
149
$ typeHasProperty ->yes () ? [] : [
@@ -174,7 +174,7 @@ public function accepts(Type $type, bool $strictTypes): AcceptsResult
174
174
175
175
$ result = $ result ->and ($ hasProperty );
176
176
try {
177
- $ otherProperty = $ type ->getProperty ($ propertyName , $ scope );
177
+ $ otherProperty = $ type ->getProperty (( string ) $ propertyName , $ scope );
178
178
} catch (MissingPropertyFromReflectionException ) {
179
179
return AcceptsResult::createNo (
180
180
[
@@ -260,7 +260,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
260
260
$ result = IsSuperTypeOfResult::createYes ();
261
261
$ scope = new OutOfClassScope ();
262
262
foreach ($ this ->properties as $ propertyName => $ propertyType ) {
263
- $ hasProperty = new IsSuperTypeOfResult ($ type ->hasProperty ($ propertyName ), []);
263
+ $ hasProperty = new IsSuperTypeOfResult ($ type ->hasProperty (( string ) $ propertyName ), []);
264
264
if ($ hasProperty ->no ()) {
265
265
if (in_array ($ propertyName , $ this ->optionalProperties , true )) {
266
266
continue ;
@@ -279,7 +279,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
279
279
280
280
$ result = $ result ->and ($ hasProperty );
281
281
try {
282
- $ otherProperty = $ type ->getProperty ($ propertyName , $ scope );
282
+ $ otherProperty = $ type ->getProperty (( string ) $ propertyName , $ scope );
283
283
} catch (MissingPropertyFromReflectionException ) {
284
284
return IsSuperTypeOfResult::createNo (
285
285
[
@@ -354,7 +354,7 @@ public function tryRemove(Type $typeToRemove): ?Type
354
354
if ($ typeToRemove instanceof HasPropertyType) {
355
355
$ properties = $ this ->properties ;
356
356
unset($ properties [$ typeToRemove ->getPropertyName ()]);
357
- $ optionalProperties = array_values (array_filter ($ this ->optionalProperties , static fn (string $ propertyName ) => $ propertyName !== $ typeToRemove ->getPropertyName ()));
357
+ $ optionalProperties = array_values (array_filter ($ this ->optionalProperties , static fn (int | string $ propertyName ) => $ propertyName !== $ typeToRemove ->getPropertyName ()));
358
358
359
359
return new self ($ properties , $ optionalProperties );
360
360
}
@@ -365,7 +365,7 @@ public function tryRemove(Type $typeToRemove): ?Type
365
365
public function makePropertyRequired (string $ propertyName ): self
366
366
{
367
367
if (array_key_exists ($ propertyName , $ this ->properties )) {
368
- $ optionalProperties = array_values (array_filter ($ this ->optionalProperties , static fn (string $ currentPropertyName ) => $ currentPropertyName !== $ propertyName ));
368
+ $ optionalProperties = array_values (array_filter ($ this ->optionalProperties , static fn (int | string $ currentPropertyName ) => $ currentPropertyName !== $ propertyName ));
369
369
370
370
return new self ($ this ->properties , $ optionalProperties );
371
371
}
@@ -383,12 +383,12 @@ public function inferTemplateTypes(Type $receivedType): TemplateTypeMap
383
383
$ typeMap = TemplateTypeMap::createEmpty ();
384
384
$ scope = new OutOfClassScope ();
385
385
foreach ($ this ->properties as $ name => $ propertyType ) {
386
- if ($ receivedType ->hasProperty ($ name )->no ()) {
386
+ if ($ receivedType ->hasProperty (( string ) $ name )->no ()) {
387
387
continue ;
388
388
}
389
389
390
390
try {
391
- $ receivedProperty = $ receivedType ->getProperty ($ name , $ scope );
391
+ $ receivedProperty = $ receivedType ->getProperty (( string ) $ name , $ scope );
392
392
} catch (MissingPropertyFromReflectionException ) {
393
393
continue ;
394
394
}
@@ -474,10 +474,10 @@ public function traverseSimultaneously(Type $right, callable $cb): Type
474
474
475
475
$ scope = new OutOfClassScope ();
476
476
foreach ($ this ->properties as $ name => $ propertyType ) {
477
- if (!$ right ->hasProperty ($ name )->yes ()) {
477
+ if (!$ right ->hasProperty (( string ) $ name )->yes ()) {
478
478
return $ this ;
479
479
}
480
- $ transformed = $ cb ($ propertyType , $ right ->getProperty ($ name , $ scope )->getReadableType ());
480
+ $ transformed = $ cb ($ propertyType , $ right ->getProperty (( string ) $ name , $ scope )->getReadableType ());
481
481
if ($ transformed !== $ propertyType ) {
482
482
$ stillOriginal = false ;
483
483
}
@@ -513,10 +513,10 @@ public function toPhpDocNode(): TypeNode
513
513
{
514
514
$ items = [];
515
515
foreach ($ this ->properties as $ name => $ type ) {
516
- if (ConstantArrayType::isValidIdentifier ($ name )) {
517
- $ keyNode = new IdentifierTypeNode ($ name );
516
+ if (ConstantArrayType::isValidIdentifier (( string ) $ name )) {
517
+ $ keyNode = new IdentifierTypeNode (( string ) $ name );
518
518
} else {
519
- $ keyPhpDocNode = (new ConstantStringType ($ name ))->toPhpDocNode ();
519
+ $ keyPhpDocNode = (new ConstantStringType (( string ) $ name ))->toPhpDocNode ();
520
520
if (!$ keyPhpDocNode instanceof ConstTypeNode) {
521
521
continue ;
522
522
}
0 commit comments