Implemented ReflectionProperty::setAccessible(), getValue() and setValue() and ReflectionClass::getStaticProperties()#343
Conversation
8b54e22 to
032bf83
Compare
032bf83 to
e181347
Compare
src/Reflection/ReflectionClass.php
Outdated
| // reasoning... | ||
| if ( ! $property->isPublic()) { | ||
| throw new PropertyNotPublic('Property is not public'); | ||
| throw PropertyDoesNotExistOrIsNotStatic::fromName($propertyName); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Ok. I just used the code that was already here :) https://github.com/Roave/BetterReflection/blob/master/src/Reflection/ReflectionClass.php#L1309
There was a problem hiding this comment.
Aye - I know my comments sometimes sound annoying and out of context, but I really just see the diffs only ^_^
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Spacing please: spaces around logical blocks :-)
There was a problem hiding this comment.
Shouldn't we populate the previous exception?
| return $default; | ||
| } | ||
| throw new CoreReflectionException($e->getMessage()); | ||
| } catch (Throwable $e) { |
| } | ||
| throw new CoreReflectionException($e->getMessage()); | ||
| } catch (Throwable $e) { | ||
| throw new CoreReflectionException($e->getMessage()); |
There was a problem hiding this comment.
Shouldn't we populate the previous exception?
| try { | ||
| $this->betterReflectionClass->setStaticPropertyValue($name, $value); | ||
| } catch (Throwable $e) { | ||
| throw new CoreReflectionException($e->getMessage()); |
There was a problem hiding this comment.
Shouldn't we populate the previous exception?
| } catch (NoObjectProvided | NotAnObject $e) { | ||
| return null; | ||
| } catch (Throwable $e) { | ||
| throw new CoreReflectionException($e->getMessage()); |
There was a problem hiding this comment.
Shouldn't we populate the previous exception?
| { | ||
| $this->assertAccessibility(); | ||
|
|
||
| $declaringClassName = $this->getDeclaringClass()->getName(); |
| */ | ||
| public function getValue($object = null) | ||
| { | ||
| $this->assertAccessibility(); |
There was a problem hiding this comment.
IMO, our own implementation should drop the setAccessible() bullcrap
There was a problem hiding this comment.
Done. setAccessible() implemented only in adapters.
| $this->assertClassExist($declaringClassName); | ||
|
|
||
| return Closure::bind(function (string $propertyName) { | ||
| return self::${$propertyName}; |
There was a problem hiding this comment.
Instead of self::, use $declaringClassName
| $this->assertObject($object); | ||
|
|
||
| return Closure::bind(function (string $propertyName) { | ||
| return $this->{$propertyName}; |
There was a problem hiding this comment.
Instead of $this, use a parameter $object and call the closure with that
There was a problem hiding this comment.
(this is to confuse the static analysers less
e181347 to
c7e70d2
Compare
c7e70d2 to
f3a5103
Compare
|
@Ocramius I hope everything is ok now :) |
…ties` to `getStaticPropertiesValues`
…icProperties` to `getStaticPropertiesValues`" This reverts commit 9e82778.
|
@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. |
|
That's alright: the naming is not the end of the world here, as it would
probably be more confusing to have a different one
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
…On Sat, Sep 2, 2017 at 12:34 PM, Jaroslav Hanslík ***@***.***> wrote:
@Ocramius <https://github.com/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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#343 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakCxBpzQnWTZqMR9bCnu3pAKaZBjAks5seS8jgaJpZM4PJeHM>
.
|
No description provided.