ConditionUserInRole   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 18
ccs 6
cts 6
cp 1
rs 10
c 2
b 0
f 1
eloc 7
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A isAllowed() 0 5 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Menu;
5
6
use Nette\Security\User;
7
8
/**
9
 * ConditionUserInRole
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class ConditionUserInRole extends BaseCondition {
14
  private User $user;
15
  /** @var string */
16
  protected string $name = "role";
17
  
18
  public function __construct(User $user) {
19 1
    $this->user = $user;
20 1
  }
21
  
22
  /**
23
   * @param string $parameter Role
24
   * @throws \InvalidArgumentException
25
   */
26
  public function isAllowed($parameter = null): bool {
27 1
    if(!is_string($parameter)) {
28 1
      throw new \InvalidArgumentException("Method " . __METHOD__ . " expects string as parameter.");
29
    }
30 1
    return $this->user->isInRole($parameter);
31
  }
32
}
33
?>