Completed
Push — master ( 88f100...7f3b2c )
by Tim
40:20 queued 39:11
created

ModuleInfo::hasControlFlag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * AppserverIo\Psr\Security\Auth\Login\LoginException
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\Login;
22
23
use AppserverIo\Lang\String;
24
use AppserverIo\Collections\HashMap;
25
26
/**
27
 * Contain's information about a login module's configuration.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2015 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/appserver-io-psr/security
33
 * @link      http://www.appserver.io
34
 */
35
class ModuleInfo
36
{
37
38
    /**
39
     * The login module's class name.
40
     *
41
     * @var \AppserverIo\Lang\String
42
     */
43
    protected $type;
44
45
    /**
46
     * The login module's initialization parameters.
47
     *
48
     * @var \AppserverIo\Collections\HashMap
49
     */
50
    protected $params;
51
52
    /**
53
     * The login module's control flag, one of Required, Requisite, Sufficient or Optional.
54
     *
55
     * @var \AppserverIo\Lang\String
56
     */
57
    protected $controlFlag;
58
59
    /**
60
     * Initializes the instance with the login module name and initialization params.
61
     *
62
     * @param \AppserverIo\Lang\String         $type        The login module class name
63
     * @param \AppserverIo\Collections\HashMap $params      The parameters for the initialize() method
64
     * @param \AppserverIo\Lang\String         $controlFlag The login module's control flag
65
     */
66 3
    public function __construct(String $type, HashMap $params, String $controlFlag)
67
    {
68 3
        $this->type = $type;
0 ignored issues
show
Documentation Bug introduced by
It seems like $type can also be of type string. However, the property $type 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...
69 3
        $this->params = $params;
70 3
        $this->controlFlag = $controlFlag;
0 ignored issues
show
Documentation Bug introduced by
It seems like $controlFlag can also be of type string. However, the property $controlFlag 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...
71 3
    }
72
73
    /**
74
     * Return's the login modules class name.
75
     *
76
     * @return \AppserverIo\Lang\String The class name
77
     */
78 1
    public function getType()
79
    {
80 1
        return $this->type;
81
    }
82
83
    /**
84
     * Return's the login modules initialization parameters.
85
     *
86
     * @return \AppserverIo\Collections\HashMap The parameters
87
     */
88 1
    public function getParams()
89
    {
90 1
        return $this->params;
91
    }
92
93
    /**
94
     * Return's the login module's control flag.
95
     *
96
     * @return \AppserverIo\Lang\String The control flag
97
     */
98 1
    public function getControlFlag()
99
    {
100 1
        return $this->controlFlag;
101
    }
102
103
    /**
104
     * Queries whether or not the login module has the passed control flag or not.
105
     *
106
     * @param \AppserverIo\Lang\String $controlFlag TRUE if the login module has the control flag, else FALSE
107
     *
108
     * @return boolean TRUE if the passed control flag matches, else FALSE
109
     */
110 1
    public function hasControlFlag(String $controlFlag)
111
    {
112 1
        return $this->controlFlag->equals($controlFlag);
0 ignored issues
show
Bug introduced by
It seems like $controlFlag defined by parameter $controlFlag on line 110 can also be of type string; however, AppserverIo\Lang\String::equals() does only seem to accept object<AppserverIo\Lang\Object>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
113
    }
114
}
115