for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Carbon_Fields\Container\Condition;
/**
* Check if user has a specific role
*
* Operator "CUSTOM" is passed an array of all user roles
*/
class User_Role_Condition extends Condition {
* Get roles for a user from the environment
* @param array $environment
* @return array<string>
protected function get_user_roles( $environment ) {
return $environment['roles'];
}
* Check if the condition is fulfilled
* @return bool
public function is_fulfilled( $environment ) {
$roles = $this->get_user_roles( $environment );
switch ( $this->get_comparison_operator() ) {
case '=':
return in_array( $this->get_value(), $roles );
break;
break
The break statement is not necessary if it is preceded for example by a return statement:
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case '!=':
return ! in_array( $this->get_value(), $roles );
case 'IN':
return count( array_intersect( $roles, $this->get_value() ) ) > 0;
case 'NOT IN':
return count( array_intersect( $roles, $this->get_value() ) ) === 0;
return $this->first_supported_comparer_is_correct(
$roles,
$this->get_comparison_operator(),
$this->get_value()
);
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.