Passed
Pull Request — master (#1108)
by Tim
06:37
created

ManagerNode::getObjectDescription()   A

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 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * \AppserverIo\Appserver\Core\Api\Node\ManagerNode
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\Core\Api\Node;
22
23
use AppserverIo\Description\Annotations as DI;
24
use AppserverIo\Description\Api\Node\AbstractNode;
25
use AppserverIo\Description\Api\Node\ParamsNodeTrait;
26
27
/**
28
 * DTO to transfer a manager.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2015 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/appserver-io/appserver
34
 * @link      http://www.appserver.io
35
 */
36
class ManagerNode extends AbstractNode implements ManagerNodeInterface
37
{
38
39
    /**
40
     * A params node trait.
41
     *
42
     * @var \AppserverIo\Description\Api\Node\ParamsNodeTrait
43
     */
44
    use ParamsNodeTrait;
45
46
    /**
47
     * A security domains node trait.
48
     *
49
     * @var \AppserverIo\Appserver\Core\Api\Node\SecurityDomainsNodeTrait
50
     */
51
    use SecurityDomainsNodeTrait;
52
53
    /**
54
     * A authenticators node trait.
55
     *
56
     * @var \AppserverIo\Appserver\Core\Api\Node\AuthenticatorsNodeTrait
57
     */
58
    use AuthenticatorsNodeTrait;
59
60
    /**
61
     * A session handlers node trait.
62
     *
63
     * @var \AppserverIo\Appserver\Core\Api\Node\SessionHandlersNodeTrait
64
     */
65
    use SessionHandlersNodeTrait;
66
67
    /**
68
     * The object description configuration.
69
     *
70
     * @var array
71
     * @DI\Mapping(nodeName="objectDescription", nodeType="AppserverIo\Appserver\Core\Api\Node\ObjectDescriptionNode")
72
     */
73
    protected $objectDescription;
74
75
    /**
76
     * The unique manager name.
77
     *
78
     * @var string
79
     * @DI\Mapping(nodeType="string")
80
     */
81
    protected $name;
82
83
    /**
84
     * The manager class name.
85
     *
86
     * @var string
87
     * @DI\Mapping(nodeType="string")
88
     */
89
    protected $type;
90
91
    /**
92
     * The managers factory class name.
93
     *
94
     * @var string
95
     * @DI\Mapping(nodeType="string")
96
     */
97
    protected $factory;
98
99
    /**
100
     * The context factory class name.
101
     *
102
     * @var string
103
     * @DI\Mapping(nodeType="string")
104
     */
105
    protected $contextFactory;
106
107
    /**
108
     * Initializes the manager configuration with the passed values.
109
     *
110
     * @param string                                                     $name              The unique manager name
111
     * @param string                                                     $type              The manager class name
112
     * @param string                                                     $factory           The managers factory class name
113
     * @param string                                                     $contextFactory    The context factory class name
114
     * @param \AppserverIo\Appserver\Core\Api\Node\ObjectDescriptionNode $objectDescription The object description configuration
115
     */
116
    public function __construct($name = '', $type = '', $factory = '', $contextFactory = '', $objectDescription = null)
117
    {
118
        $this->name = $name;
119
        $this->type = $type;
120
        $this->factory = $factory;
121
        $this->contextFactory = $contextFactory;
122
        $this->objectDescription = $objectDescription;
0 ignored issues
show
Documentation Bug introduced by
It seems like $objectDescription can also be of type AppserverIo\Appserver\Co...e\ObjectDescriptionNode. However, the property $objectDescription is declared as type array. 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...
123
    }
124
125
    /**
126
     * Returns the application name.
127
     *
128
     * @return string The unique application name
129
     */
130
    public function getName()
131
    {
132
        return $this->name;
133
    }
134
135
    /**
136
     * Returns the class name.
137
     *
138
     * @return string The class name
139
     */
140
    public function getType()
141
    {
142
        return $this->type;
143
    }
144
145
    /**
146
     * Returns the factory class name.
147
     *
148
     * @return string The factory class name
149
     */
150
    public function getFactory()
151
    {
152
        return $this->factory;
153
    }
154
155
    /**
156
     * Returns the context factory class name.
157
     *
158
     * @return string The context factory class name
159
     */
160
    public function getContextFactory()
161
    {
162
        return $this->contextFactory;
163
    }
164
165
    /**
166
     * Returns the manager's object description configuration.
167
     *
168
     * @return array|\AppserverIo\Appserver\Core\Api\Node\ObjectDescriptionNode The object description configuration
169
     */
170
    public function getObjectDescription()
171
    {
172
        return $this->objectDescription;
173
    }
174
175
    /**
176
     * This method merges the configuration of the passed manager node
177
     * into this one.
178
     *
179
     * @param \AppserverIo\Appserver\Core\Api\Node\ManagerNodeInterface $managerNode The node with the manager configuration we want to merge
180
     *
181
     * @return void
182
     */
183
    public function merge(ManagerNodeInterface $managerNode)
184
    {
185
186
        // make sure, we only merge nodes with the same name
187
        if (strcasecmp($this->getName(), $managerNode->getName()) !== 0) {
188
            return;
189
        }
190
191
        // override type and factory attributes
192
        $this->type = $managerNode->getType();
193
        $this->factory = $managerNode->getFactory();
194
        $this->contextFactory = $managerNode->getContextFactory();
195
        $this->objectDescription = $managerNode->getObjectDescription();
0 ignored issues
show
Documentation Bug introduced by
It seems like $managerNode->getObjectDescription() can also be of type AppserverIo\Appserver\Co...e\ObjectDescriptionNode. However, the property $objectDescription is declared as type array. 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...
196
197
        // load the authenticators of this manager node
198
        $localAuthenticators = $this->getAuthenticators();
199
200
        // iterate over the authenticator nodes of the passed manager node and merge them
201
        foreach ($managerNode->getAuthenticators() as $authenticatorNode) {
202
            $isMerged = false;
203
            foreach ($localAuthenticators as $key => $localAuthenticator) {
204
                if (strcasecmp($localAuthenticator->getName(), $authenticatorNode->getName()) === 0) {
205
                    $localAuthenticators[$key] = $authenticatorNode;
206
                    $isMerged = true;
207
                }
208
            }
209
            if ($isMerged === false) {
210
                $localAuthenticators[$authenticatorNode->getUuid()] = $authenticatorNode;
211
            }
212
        }
213
214
        // override the authenticators with the merged mones
215
        $this->authenticators = $localAuthenticators;
216
217
        // override the params if available
218
        if (sizeof($params = $managerNode->getParams()) > 0) {
219
            $this->params = $params;
220
        }
221
222
        // override the security domains if available
223
        if (sizeof($securityDomains = $managerNode->getSecurityDomains()) > 0) {
224
            $this->securityDomains = $securityDomains;
225
        }
226
    }
227
}
228