Completed
Push — master ( ab21ee...9f62da )
by Jakub
01:59
created

ConditionUserInRole::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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
class ConditionUserInRole extends BaseCondition {
14
  /** @var  User */
15
  protected $user;
16
  /** @var string */
17
  protected $name = "role";
18
  
19
  public function __construct(User $user) {
20 1
    $this->user = $user;
21 1
  }
22
  
23
  /**
24
   * @param string $parameter Role
1 ignored issue
show
Documentation introduced by
Should the type for parameter $parameter not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
25
   * @throws \InvalidArgumentException
26
   */
27
  public function isAllowed($parameter = NULL): bool {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after closing parenthesis; found 0
Loading history...
28 1
    if(!is_string($parameter)) {
29 1
      throw new \InvalidArgumentException("Method " . static::class . "::isAllowed expects string as parameter.");
30
    }
31 1
    return $this->user->isInRole($parameter);
32
  }
33
}
34
?>