HasGroup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 24
loc 24
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A evaluate() 15 15 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}