ConditionUserLoggedIn::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
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
final class ConditionUserLoggedIn extends BaseCondition {
14
  private User $user;
15
  /** @var string */
16
  protected string $name = "loggedIn";
17
  
18
  public function __construct(User $user) {
19 1
    $this->user = $user;
20 1
  }
21
  
22
  /**
23
   * @param bool|null $parameter
24
   * @throws \InvalidArgumentException
25
   */
26
  public function isAllowed($parameter = null): bool {
27 1
    if($parameter === null) {
28 1
      return true;
29 1
    } elseif(!is_bool($parameter)) {
30 1
      throw new \InvalidArgumentException("Method " . __METHOD__ . " expects boolean as parameter.");
31
    }
32 1
    return ($parameter === $this->user->isLoggedIn());
33
  }
34
}
35
?>