NobodyPrincipal::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * AppserverIo\Appserver\ServletEngine\Security\NobodyPrincipal
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2015 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/appserver
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Appserver\ServletEngine\Security;
22
23
use AppserverIo\Lang\String;
24
use AppserverIo\Psr\Security\PrincipalInterface;
25
26
/**
27
 * An implementation of Principal and Comparable that represents any role.
28
 * Any Principal or name of a Principal when compared to an NobodyPrincipal
29
 * using {@link #equals(PrincipleInterface) equals} will always be found
30
 * not equal to the NobodyPrincipal.
31
 *
32
 * @author    Tim Wagner <[email protected]>
33
 * @copyright 2015 TechDivision GmbH <[email protected]>
34
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
35
 * @link      https://github.com/appserver-io/appserver
36
 * @link      http://www.appserver.io
37
 */
38
class NobodyPrincipal implements PrincipalInterface
39
{
40
41
    /**
42
     * The principal name.
43
     *
44
     * @var \AppserverIo\Lang\String
45
     */
46
    const NOBODY = '<NOBODY>';
47
48
    /**
49
     * Compare this NobodyPrincipal's name against another Principal.
50
     *
51
     * @param PrincipalInterface $another The other principal to compare to
52
     *
53
     * @return boolean Will always return FALSE, because this is nobody
54
     */
55
    public function equals(PrincipalInterface $another)
56
    {
57
        return false;
58
    }
59
60
    /**
61
     * Returns the principals name as string.
62
     *
63
     * @return string The principal's name
64
     */
65
    public function __toString()
66
    {
67
        return $this->getName();
68
    }
69
70
    /**
71
     * Return's the principals name as String.
72
     *
73
     * @return \AppserverIo\Lang\String The principal's name
74
     */
75
    public function getName()
76
    {
77
        return new String(NobodyPrincipal::NOBODY);
78
    }
79
}
80