-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Rbac::getRole() : check object->getName() #5973
Conversation
if ((is_string($objectOrName) && $leaf->getName() == $objectOrName) || $leaf == $objectOrName) { | ||
if ((is_string($objectOrName) && $leaf->getName() == $objectOrName) | ||
|| (is_object($objectOrName) && $leaf->getName() == $objectOrName->getName()) | ||
|| $leaf == $objectOrName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if the line is still necessary, but don't want to remove it to avoid BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is useless. If names are different, then the objects are different as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the CS check fails, you should move ) {
to the next line.
@jmleroux got a test to back this patch? |
In a few days. 😉 |
@Ocramius here are the modified tests |
protected $index = 0; | ||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing empty line before this line.
ping @Ocramius |
@jmleroux the PR needs a rebase |
@@ -42,7 +48,7 @@ public function next() | |||
* (PHP 5 >= 5.0.0)<br/> | |||
* Return the key of the current element | |||
* @link http://php.net/manual/en/iterator.key.php | |||
* @return scalar scalar on success, or null on failure. | |||
* @return int|null scalar on success, or null on failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scalar
is not a valid php type
@Ocramius |
if ((is_string($objectOrName) && $leaf->getName() == $objectOrName) || $leaf == $objectOrName) { | ||
/** @var RoleInterface $leaf */ | ||
if ((is_string($objectOrName) && $leaf->getName() == $objectOrName) | ||
|| (is_object($objectOrName) && $leaf->getName() == $objectOrName->getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point we can be sure that objectOrName
is an object so the use of is_object is unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say you should convert object -> string before this loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truth. This can be done while validating the argument. Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say you should convert object -> string before this loop
👍
Why did you not said it first ! 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized it now :D
We know that
$objectOrName
, can only bestring
orRoleInterface
.So if it's an object, we can check with
getName()
method.If found it usefull for some unit tests which did not pass because
$leaf
and$objectOrName
were not the same when$objectOrName
was a mock.In this case, the test
$leaf == $objectOrName
was false when it should be true because the two objects had the same name property, even if the rest of the objects were different.