1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SimpleSAML\Module\monitor\TestCase; |
4
|
|
|
|
5
|
|
|
use \SimpleSAML\Module\monitor\State as State; |
6
|
|
|
use \SimpleSAML\Module\monitor\TestData as TestData; |
7
|
|
|
use \SimpleSAML\Module\monitor\TestResult as TestResult; |
8
|
|
|
|
9
|
|
|
class Module extends \SimpleSAML\Module\monitor\TestCaseFactory |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $parsed; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array|null |
18
|
|
|
*/ |
19
|
|
|
private $available; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string|null |
23
|
|
|
*/ |
24
|
|
|
private $module; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param TestData $testData |
28
|
|
|
* |
29
|
|
|
* @return void |
30
|
|
|
*/ |
31
|
|
|
protected function initialize($testData) |
32
|
|
|
{ |
33
|
|
|
$this->module = $testData->getInput('required'); |
|
|
|
|
34
|
|
|
$this->available = $testData->getInput('available'); |
35
|
|
|
$this->parsed = explode('|', $this->module); |
|
|
|
|
36
|
|
|
|
37
|
|
|
parent::initialize($testData); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
public function invokeTest() |
44
|
|
|
{ |
45
|
|
|
$testResult = new TestResult($this->getCategory(), $this->getModuleName()); |
46
|
|
|
|
47
|
|
|
$state = State::ERROR; |
48
|
|
|
$available = $this->getAvailable(); |
49
|
|
|
|
50
|
|
|
foreach ($this->parsed as $module) { |
51
|
|
|
if (in_array($module, $available)) { |
52
|
|
|
$state = State::OK; |
53
|
|
|
break 1; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if ($state == State::OK) { |
58
|
|
|
$testResult->setMessage('Module loaded'); |
59
|
|
|
} else { |
60
|
|
|
$testResult->setMessage('Module not loaded'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$testResult->setState($state); |
64
|
|
|
$this->setTestResult($testResult); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return array|null |
69
|
|
|
*/ |
70
|
|
|
private function getAvailable() |
71
|
|
|
{ |
72
|
|
|
assert(is_array($this->available)); |
73
|
|
|
return $this->available; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return string |
78
|
|
|
*/ |
79
|
|
|
private function getModule() |
80
|
|
|
{ |
81
|
|
|
assert(is_string($this->module)); |
82
|
|
|
return $this->module; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getModuleName() |
89
|
|
|
{ |
90
|
|
|
$available = $this->available; |
91
|
|
|
|
92
|
|
|
foreach ($this->parsed as $module) { |
93
|
|
|
if (in_array($module, $available)) { |
|
|
|
|
94
|
|
|
return $module; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->getModule(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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.