1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2018 SURFnet B.V. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\Stepup\Configuration\Value; |
20
|
|
|
|
21
|
|
|
use JsonSerializable; |
22
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
23
|
|
|
|
24
|
|
|
class NumberOfTokensPerIdentityOption implements JsonSerializable |
25
|
|
|
{ |
26
|
|
|
const DISABLED = 0; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
*/ |
31
|
|
|
private $numberOfTokensPerIdentity; |
32
|
|
|
|
33
|
|
|
public static function getDefault() |
34
|
|
|
{ |
35
|
|
|
return new self(self::DISABLED); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function __construct($numberOfTokensPerIdentity) |
39
|
|
|
{ |
40
|
|
|
if (!is_numeric($numberOfTokensPerIdentity)) { |
41
|
|
|
throw InvalidArgumentException::invalidType( |
42
|
|
|
'integer', |
43
|
|
|
'numberOfTokensPerIdentity', |
44
|
|
|
$numberOfTokensPerIdentity |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->numberOfTokensPerIdentity = $numberOfTokensPerIdentity; |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param NumberOfTokensPerIdentityOption $other |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
public function equals(NumberOfTokensPerIdentityOption $other) |
56
|
|
|
{ |
57
|
|
|
return $this->numberOfTokensPerIdentity === $other->numberOfTokensPerIdentity; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return bool |
62
|
|
|
*/ |
63
|
|
|
public function isEnabled() |
64
|
|
|
{ |
65
|
|
|
return $this->numberOfTokensPerIdentity > self::DISABLED; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return int |
70
|
|
|
*/ |
71
|
|
|
public function getNumberOfTokensPerIdentity() |
72
|
|
|
{ |
73
|
|
|
return $this->numberOfTokensPerIdentity; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function jsonSerialize() |
77
|
|
|
{ |
78
|
|
|
return $this->numberOfTokensPerIdentity; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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 theid
property of an instance of theAccount
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.