Completed
Push — master ( c4606f...2cda3d )
by
unknown
15:54 queued 06:31
created

User_Role_Condition::is_fulfilled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Carbon_Fields\Container\Condition;
4
5
/**
6
 * Check if user has a specific role
7
 *
8
 * Operator "CUSTOM" is passed an array of all user roles
9
 */
10
class User_Role_Condition extends Condition {
11
12
	/**
13
	 * Get roles for a user from the environment
14
	 *
15
	 * @param  array         $environment
16
	 * @return array<string>
17
	 */
18
	protected function get_user_roles( $environment ) {
19
		return $environment['roles'];
20
	}
21
22
	/**
23
	 * Check if the condition is fulfilled
24
	 *
25
	 * @param  array $environment
26
	 * @return bool
27
	 */
28
	public function is_fulfilled( $environment ) {
29
		$roles = $this->get_user_roles( $environment );
30
31
		return $this->compare(
32
			$roles,
33
			$this->get_comparison_operator(),
34
			$this->get_value()
35
		);
36
	}
37
}