Passed
Push — master ( 13f577...04b25a )
by Filippo
03:34
created

Guest::isGuest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file Guest.php
5
 * @brief This file contains the Guest class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
namespace Daikengo\User;
12
13
14
use Daikengo\Role\GuestRole;
15
use Daikengo\Permission\IPermission;
16
use Daikengo\Collection\RoleCollection;
17
18
19
/**
20
 * @brief This class represents an anonymous user.
21
 * @nosubgrouping
22
 */
23
final class Guest implements IUser {
24
25
26
  /**
27
   * @brief This implementation returns always `null`.
28
   * @return null
29
   */
30
  public function getId() {
31
    return NULL;
32
  }
33
34
35
  /**
36
   * @brief This implementation returns always `false`.
37
   * @param[in] string $id The id to match.
38
   * @return bool
39
   */
40
  public function match($id) {
41
    return FALSE;
42
  }
43
44
45
  /**
46
   * @copydoc IUser::has()
47
   */
48
  public function has(IPermission $permission) {
49
    $role = new GuestRole();
50
51
    $permissionReflection = new \ReflectionObject($permission);
52
53
    if ($permissionReflection->hasMethod('checkForGuestRole')) { // If a method exists for the roleName...
54
      // Gets the method.
55
      $method = $permissionReflection->getMethod('checkForGuestRole');
56
57
      $permission->setRole($role);
58
59
      // Invokes the method.
60
      return $method->invoke($permission);
61
    }
62
    else
63
      return FALSE;
64
  }
65
66
67
  /**
68
   * @brief This implementation returns always `true`.
69
   * @return bool
70
   */
71
  public function isGuest() {
72
    return TRUE;
73
  }
74
75
76
  /**
77
   * @brief This implementation returns always `false`.
78
   * @return bool
79
   */
80
  public function isMember() {
81
    return FALSE;
82
  }
83
84
85
  /**
86
   * @brief This method is never called for this class, but in case it will return an empty collection.
87
   * @return RoleCollection
88
   */
89
  public function getRoles() {
90
    $roles = [];
91
    return new RoleCollection('roles', $roles);
92
  }
93
94
}