Skip to content

Implemented ReflectionProperty::setAccessible(), getValue() and setValue() and ReflectionClass::getStaticProperties()#343

Merged
Ocramius merged 2 commits intoRoave:masterfrom
kukulich:property-value
Sep 2, 2017
Merged

Implemented ReflectionProperty::setAccessible(), getValue() and setValue() and ReflectionClass::getStaticProperties()#343
Ocramius merged 2 commits intoRoave:masterfrom
kukulich:property-value

Conversation

@kukulich
Copy link
Copy Markdown
Collaborator

No description provided.

@kukulich kukulich force-pushed the property-value branch 4 times, most recently from 8b54e22 to 032bf83 Compare September 1, 2017 08:55
@kukulich kukulich changed the title Implemented ReflectionProperty::setAccessible(), getValue() and setValue() Implemented ReflectionProperty::setAccessible(), getValue() and setValue() and ReflectionClass::getStaticProperties() Sep 1, 2017
// reasoning...
if ( ! $property->isPublic()) {
throw new PropertyNotPublic('Property is not public');
throw PropertyDoesNotExistOrIsNotStatic::fromName($propertyName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You know if it does not exist or if it is static, so throwing a PropertyDoesNotExistOrIsNotStatic feels wrong.

A better way to handle this is having PropertyDoesNotExistOrIsNotStatic be an abstract class, and then have two subtypes for the actual failure: that would make it much easier to deal with for a consumer, and would read more sensibly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aye - I know my comments sometimes sound annoying and out of context, but I really just see the diffs only ^_^

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's ok :) I hope I will someday prepare a pull request that can be merged straight away :)

if (2 === \func_num_args()) {
return $default;
}
throw new CoreReflectionException($e->getMessage());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Spacing please: spaces around logical blocks :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we populate the previous exception?

return $default;
}
throw new CoreReflectionException($e->getMessage());
} catch (Throwable $e) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When can this happen?

}
throw new CoreReflectionException($e->getMessage());
} catch (Throwable $e) {
throw new CoreReflectionException($e->getMessage());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we populate the previous exception?

try {
$this->betterReflectionClass->setStaticPropertyValue($name, $value);
} catch (Throwable $e) {
throw new CoreReflectionException($e->getMessage());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we populate the previous exception?

} catch (NoObjectProvided | NotAnObject $e) {
return null;
} catch (Throwable $e) {
throw new CoreReflectionException($e->getMessage());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't we populate the previous exception?

{
$this->assertAccessibility();

$declaringClassName = $this->getDeclaringClass()->getName();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Scenario to check: https://3v4l.org/8fBDe

*/
public function getValue($object = null)
{
$this->assertAccessibility();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO, our own implementation should drop the setAccessible() bullcrap

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. setAccessible() implemented only in adapters.

$this->assertClassExist($declaringClassName);

return Closure::bind(function (string $propertyName) {
return self::${$propertyName};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of self::, use $declaringClassName

$this->assertObject($object);

return Closure::bind(function (string $propertyName) {
return $this->{$propertyName};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of $this, use a parameter $object and call the closure with that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(this is to confuse the static analysers less

@kukulich
Copy link
Copy Markdown
Collaborator Author

kukulich commented Sep 1, 2017

@Ocramius I hope everything is ok now :)

@Ocramius Ocramius merged commit f3a5103 into Roave:master Sep 2, 2017
Ocramius added a commit that referenced this pull request Sep 2, 2017
Ocramius added a commit that referenced this pull request Sep 2, 2017
…icProperties` to `getStaticPropertiesValues`"

This reverts commit 9e82778.
Ocramius added a commit that referenced this pull request Sep 2, 2017
Ocramius added a commit that referenced this pull request Sep 2, 2017
@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 2, 2017

@kukulich merged, thanks! I tried to improve something in 9e82778, but failed due to how the test is (reasonably) designed.

🚢 and thanks!

@Ocramius Ocramius assigned Ocramius and unassigned kukulich Sep 2, 2017
@kukulich
Copy link
Copy Markdown
Collaborator Author

kukulich commented Sep 2, 2017

@Ocramius I'm only on mobile now but if I understand it well then remove this line https://github.com/Roave/BetterReflection/blob/master/test/unit/Reflection/Adapter/ReflectionClassTest.php#L90 and implement special test for "getStaticProperties". Some other methods are already tested in similar way.

@kukulich kukulich deleted the property-value branch September 2, 2017 10:34
@Ocramius
Copy link
Copy Markdown
Member

Ocramius commented Sep 2, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants