Code Duplication    Length = 24-25 lines in 2 locations

src/Psecio/Invoke/Match/User/HasGroup.php 1 location

@@ 5-28 (lines=24) @@
2
3
namespace Psecio\Invoke\Match\User;
4
5
class HasGroup extends \Psecio\Invoke\MatchInstance
6
{
7
	/**
8
	 * Evaluate the group (or name) provided to see if there's a match
9
	 *
10
	 * @param string|\Psecio\Invoke\GroupInterface $data Group name or instance
11
	 * @return boolean Pass/fail status of the evaluation
12
	 */
13
	public function evaluate($data)
14
	{
15
		$groups = $this->getConfig('data');
16
		$userGroups = $data->user->getGroups();
17
18
		// If any are objects, transform to strings
19
		foreach ($userGroups as $index => $group) {
20
			$userGroups[$index] = ($group instanceof \Psecio\Invoke\GroupInterface)
21
				? $group->getName() : $group;
22
		}
23
24
		// Find the intersection
25
		$match = array_intersect($groups, $userGroups);
26
		return (count($match) === count($groups));
27
	}
28
}

src/Psecio/Invoke/Match/User/HasPermission.php 1 location

@@ 5-29 (lines=25) @@
2
3
namespace Psecio\Invoke\Match\User;
4
5
class HasPermission extends \Psecio\Invoke\MatchInstance
6
{
7
	/**
8
	 * Evaluate the provided permission instance (or name) against provided
9
	 * 	for a match
10
	 *
11
	 * @param string|\Psecio\Invoke\PermissionInterface $data Permission data
12
	 * @return boolean Pass/fail status of evaluation
13
	 */
14
	public function evaluate($data)
15
	{
16
		$permissions = $this->getConfig('data');
17
		$userPermissions = $data->user->getPermissions();
18
19
		// If any are objects, transform to strings
20
		foreach ($userPermissions as $index => $permission) {
21
			$userPermissions[$index] = ($permission instanceof \Psecio\Invoke\PermissionInterface)
22
				? $permission->getName() : $permission;
23
		}
24
25
		// Find the intersection
26
		$match = array_intersect($permissions, $userPermissions);
27
		return (count($match) === count($permissions));
28
	}
29
}