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

ConditionPermission   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 24
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isAllowed() 0 8 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Menu;
5
6
use Nette\Security\User,
7
    Nette\Utils\Strings;
8
9
/**
10
 * ConditionPermission
11
 *
12
 * @author Jakub Konečný
13
 */
14 1
class ConditionPermission extends BaseCondition {
15
  /** @var  User */
16
  protected $user;
17
  /** @var string */
18
  protected $name = "acl";
19
  
20
  public function __construct(User $user) {
21 1
    $this->user = $user;
22 1
  }
23
  
24
  /**
25
   * @param string $parameter
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...
26
   * @throws \InvalidArgumentException
27
   * @throws \OutOfBoundsException
28
   */
29
  public function isAllowed($parameter = NULL): bool {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after closing parenthesis; found 0
Loading history...
30 1
    if(!is_string($parameter)) {
31 1
      throw new \InvalidArgumentException("Method " . static::class . "::isAllowed expects string as parameter.");
32 1
    } elseif(!Strings::contains($parameter, ":")) {
33 1
      throw new \OutOfBoundsException("Method " . static::class . "::isAllowed expects parameter in format resource:privilege.");
34
    }
35 1
    return $this->user->isAllowed(Strings::before($parameter, ":"), Strings::after($parameter, ":"));
36
  }
37
}
38
?>