Cancelled
Branch master (244451)
by Tim
10:31
created

ServerGroup::initialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestCase\Store\Memcache;
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
final class ServerGroup extends \SimpleSAML\Module\monitor\TestCaseFactory
10
{
11
    /**
12
     * @var array
13
     */
14
    private $results = array();
15
16
    /**
17
     * @var string|null
18
     */
19
    private $group = null;
20
21
    /**
22
     * @param TestData $testData
23
     *
24
     * @return void
25
     */
26
    protected function initialize($testData)
27
    {
28
        $results = $testData->getInput('results');
29
        $this->$results = \SimpleSAML\Utils\Arrays::Arrayize($results);
30
        $this->group = $testData->getInput('group');
0 ignored issues
show
Documentation Bug introduced by
It seems like $testData->getInput('group') can also be of type array. However, the property $group is declared as type null|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...
31
32
        parent::initialize($testData);
33
    }
34
35
    /**
36
     * @return void
37
     */
38
    public function invokeTest()
39
    {
40
        $testResult = new TestResult('Memcache Server Group Health', 'Group ' . $this->group);
41
42
        $states = array();
43
        foreach ($this->results as $result) {
44
            $states[] = $result->getState();
45
        }
46
        $state = min($states);
47
48
        $testResult->setState($state);
49
50
        if ($state === State::OK) {
51
            $testResult->setMessage('Group is healthy');
52
        } elseif ($state === State::WARNING) {
53
            $testResult->setMessage('Group is crippled');
54
        } else {
55
            $testResult->setMessage('Group is down');
56
        }
57
58
        $this->setTestResult($testResult);
59
    }
60
}
61