diff --git a/src/PseudoTypes/PrivatePropertiesOf.php b/src/PseudoTypes/PrivatePropertiesOf.php new file mode 100644 index 0000000..bcf8f84 --- /dev/null +++ b/src/PseudoTypes/PrivatePropertiesOf.php @@ -0,0 +1,27 @@ +type . '>'; + } +} diff --git a/src/PseudoTypes/PropertiesOf.php b/src/PseudoTypes/PropertiesOf.php new file mode 100644 index 0000000..644ae88 --- /dev/null +++ b/src/PseudoTypes/PropertiesOf.php @@ -0,0 +1,53 @@ +type = $type; + } + + public function getType(): Type + { + return $this->type; + } + + public function underlyingType(): Type + { + return new Array_(new Mixed_(), new String_()); + } + + public function __toString(): string + { + return 'properties-of<' . $this->type . '>'; + } +} diff --git a/src/PseudoTypes/ProtectedPropertiesOf.php b/src/PseudoTypes/ProtectedPropertiesOf.php new file mode 100644 index 0000000..74ef8de --- /dev/null +++ b/src/PseudoTypes/ProtectedPropertiesOf.php @@ -0,0 +1,27 @@ +type . '>'; + } +} diff --git a/src/PseudoTypes/PublicPropertiesOf.php b/src/PseudoTypes/PublicPropertiesOf.php new file mode 100644 index 0000000..eef0491 --- /dev/null +++ b/src/PseudoTypes/PublicPropertiesOf.php @@ -0,0 +1,27 @@ +type . '>'; + } +} diff --git a/src/TypeResolver.php b/src/TypeResolver.php index f7ab9bd..b122f2c 100644 --- a/src/TypeResolver.php +++ b/src/TypeResolver.php @@ -50,6 +50,10 @@ use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem; use phpDocumentor\Reflection\PseudoTypes\OffsetAccess; use phpDocumentor\Reflection\PseudoTypes\PositiveInteger; +use phpDocumentor\Reflection\PseudoTypes\PrivatePropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\PropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\ProtectedPropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\PublicPropertiesOf; use phpDocumentor\Reflection\PseudoTypes\Scalar; use phpDocumentor\Reflection\PseudoTypes\StringValue; use phpDocumentor\Reflection\PseudoTypes\TraitString; @@ -440,6 +444,18 @@ private function createFromGeneric(GenericTypeNode $type, Context $context): Typ case 'value-of': return new ValueOf($this->createType($type->genericTypes[0], $context)); + case 'properties-of': + return new PropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'public-properties-of': + return new PublicPropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'protected-properties-of': + return new ProtectedPropertiesOf($this->createType($type->genericTypes[0], $context)); + + case 'private-properties-of': + return new PrivatePropertiesOf($this->createType($type->genericTypes[0], $context)); + case 'int-mask': return new IntMask(...$this->createTypesByTypeNodes($type->genericTypes, $context)); diff --git a/tests/unit/PseudoTypes/PrivatePropertiesOfTest.php b/tests/unit/PseudoTypes/PrivatePropertiesOfTest.php new file mode 100644 index 0000000..606398a --- /dev/null +++ b/tests/unit/PseudoTypes/PrivatePropertiesOfTest.php @@ -0,0 +1,18 @@ +assertSame('private-properties-of', (string) $type); + } +} diff --git a/tests/unit/PseudoTypes/PropertiesOfTest.php b/tests/unit/PseudoTypes/PropertiesOfTest.php new file mode 100644 index 0000000..dc0d03d --- /dev/null +++ b/tests/unit/PseudoTypes/PropertiesOfTest.php @@ -0,0 +1,32 @@ +assertSame($childType, $type->getType()); + $this->assertEquals(new Array_(new Mixed_(), new String_()), $type->underlyingType()); + $this->assertEquals(new String_(), $type->getKeyType()); + $this->assertEquals(new Mixed_(), $type->getValueType()); + } + + public function testToString(): void + { + $type = new PropertiesOf(new Self_()); + + $this->assertSame('properties-of', (string) $type); + } +} diff --git a/tests/unit/PseudoTypes/ProtectedPropertiesOfTest.php b/tests/unit/PseudoTypes/ProtectedPropertiesOfTest.php new file mode 100644 index 0000000..72afd31 --- /dev/null +++ b/tests/unit/PseudoTypes/ProtectedPropertiesOfTest.php @@ -0,0 +1,18 @@ +assertSame('protected-properties-of', (string) $type); + } +} diff --git a/tests/unit/PseudoTypes/PublicPropertiesOfTest.php b/tests/unit/PseudoTypes/PublicPropertiesOfTest.php new file mode 100644 index 0000000..37b3771 --- /dev/null +++ b/tests/unit/PseudoTypes/PublicPropertiesOfTest.php @@ -0,0 +1,18 @@ +assertSame('public-properties-of', (string) $type); + } +} diff --git a/tests/unit/TypeResolverTest.php b/tests/unit/TypeResolverTest.php index 6e3b17a..4919aa1 100644 --- a/tests/unit/TypeResolverTest.php +++ b/tests/unit/TypeResolverTest.php @@ -50,6 +50,10 @@ use phpDocumentor\Reflection\PseudoTypes\ObjectShapeItem; use phpDocumentor\Reflection\PseudoTypes\OffsetAccess; use phpDocumentor\Reflection\PseudoTypes\PositiveInteger; +use phpDocumentor\Reflection\PseudoTypes\PrivatePropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\PropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\ProtectedPropertiesOf; +use phpDocumentor\Reflection\PseudoTypes\PublicPropertiesOf; use phpDocumentor\Reflection\PseudoTypes\Scalar; use phpDocumentor\Reflection\PseudoTypes\StringValue; use phpDocumentor\Reflection\PseudoTypes\TraitString; @@ -1122,6 +1126,22 @@ public function genericsProvider(): array 'non-empty-list', new NonEmptyList(new Mixed_()), ], + [ + 'properties-of', + new PropertiesOf(new Self_()), + ], + [ + 'public-properties-of', + new PublicPropertiesOf(new Self_()), + ], + [ + 'protected-properties-of', + new ProtectedPropertiesOf(new Self_()), + ], + [ + 'private-properties-of', + new PrivatePropertiesOf(new Self_()), + ], ]; }