Skip to content

Commit 227de35

Browse files
committed
Cast permissions to array directly without testing
1 parent 0ae4158 commit 227de35

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed

src/Cartalyst/Sentry/Groups/Eloquent/Group.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,7 @@ public function hasAccess($permissions, $all = true)
109109
{
110110
$groupPermissions = $this->getPermissions();
111111

112-
if ( ! is_array($permissions))
113-
{
114-
$permissions = (array) $permissions;
115-
}
116-
117-
foreach ($permissions as $permission)
112+
foreach ((array) $permissions as $permission)
118113
{
119114
// We will set a flag now for whether this permission was
120115
// matched at all.

src/Cartalyst/Sentry/Groups/Kohana/Group.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,7 @@ public function hasAccess($permissions, $all = true)
122122
{
123123
$groupPermissions = $this->getPermissions();
124124

125-
if ( ! is_array($permissions) )
126-
{
127-
$permissions = (array) $permissions;
128-
}
129-
130-
foreach ($permissions as $permission)
125+
foreach ((array) $permissions as $permission)
131126
{
132127
// We will set a flag now for whether this permission was
133128
// matched at all.

src/Cartalyst/Sentry/Users/Eloquent/User.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,7 @@ public function hasPermission($permissions, $all = true)
630630
{
631631
$mergedPermissions = $this->getMergedPermissions();
632632

633-
if ( ! is_array($permissions))
634-
{
635-
$permissions = (array) $permissions;
636-
}
637-
638-
foreach ($permissions as $permission)
633+
foreach ((array) $permissions as $permission)
639634
{
640635
// We will set a flag now for whether this permission was
641636
// matched at all.

src/Cartalyst/Sentry/Users/Kohana/User.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,7 @@ public function hasPermission($permissions, $all = true)
605605
{
606606
$mergedPermissions = $this->getMergedPermissions();
607607

608-
if ( ! is_array($permissions))
609-
{
610-
$permissions = (array) $permissions;
611-
}
612-
613-
foreach ($permissions as $permission)
608+
foreach ((array) $permissions as $permission)
614609
{
615610
// We will set a flag now for whether this permission was
616611
// matched at all.

tests/EloquentGroupTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,16 @@ public function testDeletingGroupDetachesAllUserRelationships()
297297
$group->delete();
298298
}
299299

300+
public function testGroupHasAccess()
301+
{
302+
$group = new \Cartalyst\Sentry\Groups\Eloquent\Group;
303+
$group->name = 'foo';
304+
$group->permissions = array(
305+
'user.update' => 1
306+
);
307+
308+
$this->assertTrue($group->hasAccess('user.update'));
309+
$this->assertFalse($group->hasAccess('user.delete'));
310+
}
311+
300312
}

0 commit comments

Comments
 (0)