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

ConditionUserLoggedIn::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
 * ConditionUserLoggedIn
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
class ConditionUserLoggedIn extends BaseCondition {
14 1
  use \Nette\SmartObject;
15
  
16
  /** @var  User */
17
  protected $user;
18
  /** @var string */
19
  protected $name = "loggedIn";
20
  
21
  public function __construct(User $user) {
22 1
    $this->user = $user;
23 1
  }
24
  
25
  /**
26
   * @param bool $parameter
0 ignored issues
show
Documentation introduced by
Should the type for parameter $parameter not be boolean|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...
27
   * @throws \InvalidArgumentException
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_null($parameter)) {
31 1
      return true;
32 1
    } elseif(!is_bool($parameter)) {
33 1
      throw new \InvalidArgumentException("Method " . static::class . "::isAllowed expects boolean as parameter.");
34
    }
35 1
    return ($parameter === $this->user->isLoggedIn());
36
  }
37
}
38
?>