Skip to content

Commit b6fd1f1

Browse files
authored
Merge pull request #348 from greg0ire/missing-methods
Add missing proxy methods
2 parents a55fc31 + 5bed91c commit b6fd1f1

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
lines changed

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ parameters:
1010
count: 1
1111
path: src/Persistence/Reflection/EnumReflectionProperty.php
1212

13+
-
14+
message: "#^Method Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:getDeclaringClass\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
15+
count: 1
16+
path: src/Persistence/Reflection/EnumReflectionProperty.php
17+
18+
-
19+
message: "#^Method Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:getType\\(\\) should return ReflectionNamedType\\|ReflectionUnionType\\|null but returns ReflectionType\\|null\\.$#"
20+
count: 1
21+
path: src/Persistence/Reflection/EnumReflectionProperty.php
22+
1323
-
1424
message: "#^Method Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:toEnum\\(\\) should return array\\<BackedEnum\\>\\|BackedEnum but returns array\\<BackedEnum\\|int\\|string\\>\\.$#"
1525
count: 1

src/Persistence/Reflection/EnumReflectionProperty.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Doctrine\Persistence\Reflection;
66

77
use BackedEnum;
8+
use ReflectionClass;
89
use ReflectionProperty;
10+
use ReflectionType;
911
use ReturnTypeWillChange;
1012

1113
use function array_map;
@@ -30,6 +32,44 @@ public function __construct(ReflectionProperty $originalReflectionProperty, stri
3032
$this->enumType = $enumType;
3133
}
3234

35+
/**
36+
* {@inheritDoc}
37+
*
38+
* @psalm-external-mutation-free
39+
*/
40+
public function getDeclaringClass(): ReflectionClass
41+
{
42+
return $this->originalReflectionProperty->getDeclaringClass();
43+
}
44+
45+
/**
46+
* {@inheritDoc}
47+
*
48+
* @psalm-external-mutation-free
49+
*/
50+
public function getName(): string
51+
{
52+
return $this->originalReflectionProperty->getName();
53+
}
54+
55+
/**
56+
* {@inheritDoc}
57+
*
58+
* @psalm-external-mutation-free
59+
*/
60+
public function getType(): ?ReflectionType
61+
{
62+
return $this->originalReflectionProperty->getType();
63+
}
64+
65+
/**
66+
* {@inheritDoc}
67+
*/
68+
public function getAttributes(?string $name = null, int $flags = 0): array
69+
{
70+
return $this->originalReflectionProperty->getAttributes($name, $flags);
71+
}
72+
3373
/**
3474
* {@inheritDoc}
3575
*

tests_php81/Persistence/Reflection/EnumReflectionPropertyTest.php

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Doctrine\Tests_PHP81\Persistence\Reflection;
46

7+
use Attribute;
58
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
69
use PHPUnit\Framework\TestCase;
10+
use ReflectionNamedType;
711
use ReflectionProperty;
812
use ValueError;
913

@@ -20,6 +24,33 @@ public function testGetValue(): void
2024
self::assertNull($reflProperty->getValue($object));
2125
}
2226

27+
public function testGetDeclaringClass(): void
28+
{
29+
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
30+
self::assertSame(TypedEnumClass::class, $reflProperty->getDeclaringClass()->getName());
31+
}
32+
33+
public function testGetName(): void
34+
{
35+
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
36+
self::assertSame('suit', $reflProperty->getName());
37+
}
38+
39+
public function testGetType(): void
40+
{
41+
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
42+
$type = $reflProperty->getType();
43+
self::assertInstanceOf(ReflectionNamedType::class, $type);
44+
self::assertSame(Suit::class, $type->getName());
45+
}
46+
47+
public function testGetAttributes(): void
48+
{
49+
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
50+
self::assertCount(1, $reflProperty->getAttributes());
51+
self::assertSame(MyAttribute::class, $reflProperty->getAttributes()[0]->getName());
52+
}
53+
2354
public function testSetValidValue(): void
2455
{
2556
$object = new TypedEnumClass();
@@ -84,17 +115,23 @@ public function testSetEnumArray(): void
84115
}
85116
}
86117

118+
#[Attribute(Attribute::TARGET_PROPERTY)]
119+
class MyAttribute
120+
{
121+
}
122+
87123
class TypedEnumClass
88124
{
125+
#[MyAttribute]
89126
public ?Suit $suit = null;
90127

91128
public ?array $suits = null;
92129
}
93130

94131
enum Suit: string
95132
{
96-
case Hearts = 'H';
133+
case Hearts = 'H';
97134
case Diamonds = 'D';
98-
case Clubs = 'C';
99-
case Spades = 'S';
135+
case Clubs = 'C';
136+
case Spades = 'S';
100137
}

0 commit comments

Comments
 (0)