NameCallback::setName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * AppserverIo\Psr\Security\Auth\Callback\NameCallback
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-psr/security
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Psr\Security\Auth\Callback;
22
23
use AppserverIo\Lang\String;
24
25
/**
26
 * An abstract login module implementation.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2015 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/appserver-io-psr/security
32
 * @link      http://www.appserver.io
33
 */
34
class NameCallback implements CallbackInterface
35
{
36
37
    /**
38
     * The default username.
39
     *
40
     * @var string
41
     */
42
    const DEFAULT_NAME = 'guest';
43
44
    /**
45
     * The login name.
46
     *
47
     * @var \AppserverIo\Lang\String
48
     */
49
    protected $name;
50
51
    /**
52
     * The default login name to use.
53
     *
54
     * @var \AppserverIo\Lang\String
55
     */
56
    protected $defaultName;
57
58
    /**
59
     * Initialize the username callback.
60
     */
61 3
    public function __construct()
62
    {
63 3
        $this->setDefaultName(new String(NameCallback::DEFAULT_NAME));
64 3
    }
65
66
    /**
67
     * Set's the default login name.
68
     *
69
     * @param \AppserverIo\Lang\String $defaultName The default name
70
     *
71
     * @return void
72
     */
73 3
    public function setDefaultName(String $defaultName)
74
    {
75 3
        $this->defaultName = $defaultName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $defaultName can also be of type string. However, the property $defaultName is declared as type object<AppserverIo\Lang\String>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
76 3
    }
77
78
    /**
79
     * Return's the default name.
80
     *
81
     * @return \AppserverIo\Lang\String The default name
82
     */
83 2
    public function getDefaultName()
84
    {
85 2
        return $this->defaultName;
86
    }
87
88
    /**
89
     * Set's the login name.
90
     *
91
     * @param \AppserverIo\Lang\String $name The login name to set
92
     *
93
     * @return void
94
     */
95 1
    public function setName(String $name)
96
    {
97 1
        $this->name = $name;
0 ignored issues
show
Documentation Bug introduced by
It seems like $name can also be of type string. However, the property $name is declared as type object<AppserverIo\Lang\String>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
98 1
    }
99
100
    /**
101
     * Return's the login name.
102
     *
103
     * @return \AppserverIo\Lang\String The login name
104
     */
105 2
    public function getName()
106
    {
107 2
        return $this->name;
108
    }
109
}
110