HasGroup::evaluate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Psecio\Invoke\Match\User;
4
5 View Code Duplication
class HasGroup extends \Psecio\Invoke\MatchInstance
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
}