From afeadbddd7ee06d2ac07e8701e42e23b3fb404cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sun, 7 Dec 2025 10:19:19 +0400 Subject: [PATCH 1/2] Add support for `properties-of` and its variations --- src/PseudoTypes/PrivatePropertiesOf.php | 27 ++++++++++ src/PseudoTypes/PropertiesOf.php | 53 +++++++++++++++++++ src/PseudoTypes/ProtectedPropertiesOf.php | 27 ++++++++++ src/PseudoTypes/PublicPropertiesOf.php | 27 ++++++++++ src/TypeResolver.php | 16 ++++++ .../unit/PseudoTypes/PrivatePropertiesOf.php | 18 +++++++ tests/unit/PseudoTypes/PropertiesOfTest.php | 32 +++++++++++ .../PseudoTypes/ProtectedPropertiesOfTest.php | 18 +++++++ tests/unit/PseudoTypes/PublicPropertiesOf.php | 18 +++++++ tests/unit/TypeResolverTest.php | 20 +++++++ 10 files changed, 256 insertions(+) create mode 100644 src/PseudoTypes/PrivatePropertiesOf.php create mode 100644 src/PseudoTypes/PropertiesOf.php create mode 100644 src/PseudoTypes/ProtectedPropertiesOf.php create mode 100644 src/PseudoTypes/PublicPropertiesOf.php create mode 100644 tests/unit/PseudoTypes/PrivatePropertiesOf.php create mode 100644 tests/unit/PseudoTypes/PropertiesOfTest.php create mode 100644 tests/unit/PseudoTypes/ProtectedPropertiesOfTest.php create mode 100644 tests/unit/PseudoTypes/PublicPropertiesOf.php 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 79a2ba3..13dc157 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\StringValue; use phpDocumentor\Reflection\PseudoTypes\TraitString; use phpDocumentor\Reflection\PseudoTypes\True_; @@ -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/PrivatePropertiesOf.php b/tests/unit/PseudoTypes/PrivatePropertiesOf.php new file mode 100644 index 0000000..606398a --- /dev/null +++ b/tests/unit/PseudoTypes/PrivatePropertiesOf.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/PublicPropertiesOf.php b/tests/unit/PseudoTypes/PublicPropertiesOf.php new file mode 100644 index 0000000..37b3771 --- /dev/null +++ b/tests/unit/PseudoTypes/PublicPropertiesOf.php @@ -0,0 +1,18 @@ +assertSame('public-properties-of', (string) $type); + } +} diff --git a/tests/unit/TypeResolverTest.php b/tests/unit/TypeResolverTest.php index 4cd94f4..7c51e83 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\StringValue; use phpDocumentor\Reflection\PseudoTypes\TraitString; use phpDocumentor\Reflection\PseudoTypes\True_; @@ -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_()), + ], ]; } From 40ec32815736d0050ecfe1c146e4d1bf36076e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=A1=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D0=B2?= Date: Sun, 7 Dec 2025 10:21:36 +0400 Subject: [PATCH 2/2] Fix CS --- .../{PrivatePropertiesOf.php => PrivatePropertiesOfTest.php} | 0 .../{PublicPropertiesOf.php => PublicPropertiesOfTest.php} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename tests/unit/PseudoTypes/{PrivatePropertiesOf.php => PrivatePropertiesOfTest.php} (100%) rename tests/unit/PseudoTypes/{PublicPropertiesOf.php => PublicPropertiesOfTest.php} (100%) diff --git a/tests/unit/PseudoTypes/PrivatePropertiesOf.php b/tests/unit/PseudoTypes/PrivatePropertiesOfTest.php similarity index 100% rename from tests/unit/PseudoTypes/PrivatePropertiesOf.php rename to tests/unit/PseudoTypes/PrivatePropertiesOfTest.php diff --git a/tests/unit/PseudoTypes/PublicPropertiesOf.php b/tests/unit/PseudoTypes/PublicPropertiesOfTest.php similarity index 100% rename from tests/unit/PseudoTypes/PublicPropertiesOf.php rename to tests/unit/PseudoTypes/PublicPropertiesOfTest.php