Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Persistence/Reflection/RuntimeReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(string $class, string $name)
#[ReturnTypeWillChange]
public function getValue($object = null)
{
if ($object === null) {
if ($object === null || $this->isStatic()) {
return parent::getValue($object);
}

Expand All @@ -56,7 +56,7 @@ public function getValue($object = null)
#[ReturnTypeWillChange]
public function setValue($object, $value = null)
{
if (! ($object instanceof Proxy && ! $object->__isInitialized())) {
if ((! ($object instanceof Proxy && ! $object->__isInitialized())) || $this->isStatic()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra parenthesis are not necessary. You can switch the operands to remove any ambiguity.

Suggested change
if ((! ($object instanceof Proxy && ! $object->__isInitialized())) || $this->isStatic()) {
if ($this->isStatic() || ! ($object instanceof Proxy && ! $object->__isInitialized())) {

parent::setValue($object, $value);

return;
Expand Down
16 changes: 16 additions & 0 deletions tests/Persistence/RuntimeReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class RuntimeReflectionPropertyTest extends TestCase
/**
* @testWith ["test", "testValue"]
* ["privateTest", "privateTestValue"]
* ["staticTest", "staticTestValue"]
*/
public function testGetSetValue(string $name, string $value): void
{
Expand Down Expand Up @@ -64,6 +65,9 @@ public function testGetValueOnProxyProperty(string $proxyClass): void
self::assertSame('testValue', $reflProperty->getValue($mockProxy));
unset($mockProxy->checkedProperty);
self::assertNull($reflProperty->getValue($mockProxy));

$reflStaticProperty = new RuntimeReflectionProperty($proxyClass, 'staticCheckedProperty');
self::assertSame('testValue', $reflStaticProperty->getValue($mockProxy));
}

/**
Expand Down Expand Up @@ -91,6 +95,12 @@ public function testSetValueOnProxyProperty(string $proxyClass): void
$reflProperty->setValue($mockProxy, 'otherNewValue');
self::assertSame('otherNewValue', $mockProxy->checkedProperty);

$reflStaticProperty = new RuntimeReflectionProperty($proxyClass, 'staticCheckedProperty');
$reflStaticProperty->setValue($mockProxy, 'staticNewValue');
self::assertSame('staticNewValue', $mockProxy::$staticCheckedProperty);
$reflStaticProperty->setValue($mockProxy, 'staticOtherNewValue');
self::assertSame('staticOtherNewValue', $mockProxy::$staticCheckedProperty);

if (! $mockProxy instanceof CommonProxy) {
return;
}
Expand Down Expand Up @@ -126,6 +136,9 @@ class RuntimeReflectionPropertyTestProxyMock implements Proxy
/** @var string */
public $checkedProperty = 'testValue';

/** @var string */
public static $staticCheckedProperty = 'testValue';

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -249,6 +262,9 @@ class RuntimeReflectionPropertyTestClass
/** @var string|null */
private $privateTest = 'privateTestValue';

/** @var string|null */
public static $staticTest = 'staticTestValue';

public function getPrivateTest(): ?string
{
return $this->privateTest;
Expand Down
Loading