Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Sep 2, 2017

Conversation

kukulich
Copy link
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
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
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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