Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Rbac::getRole() : check object->getName() #5973

Merged
merged 2 commits into from
Mar 21, 2014
Merged

Rbac::getRole() : check object->getName() #5973

merged 2 commits into from
Mar 21, 2014

Conversation

jmleroux
Copy link
Contributor

We know that $objectOrName, can only be string or RoleInterface.

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.

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) {
Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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 jmleroux closed this Mar 14, 2014
@jmleroux jmleroux reopened this Mar 14, 2014
@Ocramius
Copy link
Member

@jmleroux got a test to back this patch?

@jmleroux
Copy link
Contributor Author

In a few days. 😉

@jmleroux
Copy link
Contributor Author

@Ocramius here are the modified tests

protected $index = 0;
/**
Copy link
Contributor

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.

@jmleroux
Copy link
Contributor Author

ping @Ocramius

@Ocramius
Copy link
Member

@jmleroux the PR needs a rebase

@@ -42,7 +48,7 @@ public function next()
* (PHP 5 &gt;= 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.
Copy link
Contributor Author

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

@jmleroux
Copy link
Contributor Author

@Ocramius
Rebased. I took the opportunity to add some minor change.

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())
Copy link
Member

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

Copy link
Contributor

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

Copy link
Member

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

Copy link
Contributor Author

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 ! 😉

Copy link
Contributor

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

@jmleroux
Copy link
Contributor Author

@Maks3w @danizord @danizord
Checking if role is an object or a string before loop

Maks3w added a commit that referenced this pull request Mar 21, 2014
Maks3w added a commit that referenced this pull request Mar 21, 2014
Maks3w added a commit that referenced this pull request Mar 21, 2014
@Maks3w Maks3w merged commit ae35ff1 into zendframework:master Mar 21, 2014
@jmleroux jmleroux deleted the permissions branch March 21, 2014 09:07
weierophinney pushed a commit to zendframework/zend-permissions-rbac that referenced this pull request May 15, 2015
weierophinney pushed a commit to zendframework/zend-permissions-rbac that referenced this pull request May 15, 2015
weierophinney pushed a commit to zendframework/zend-permissions-rbac that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants