Completed
Push — master ( aeba7d...7e87b1 )
by Tim
01:26
created

Memcache::invokeTestSuite()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 40
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 25
nc 8
nop 0
dl 0
loc 40
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
namespace SimpleSAML\Module\monitor\TestSuite\Store;
4
5
use \SimpleSAML\Module\monitor\TestCase as TestCase;
6
7
final class Memcache extends \SimpleSAML\Module\monitor\TestSuite
0 ignored issues
show
Coding Style introduced by
Memcache does not seem to conform to the naming convention (^sspmod_monitor_([A-Z][a-zA-Z0-9_]+)+$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
8
{
9
    /*
10
     * @return void
11
     */
12
    protected function initialize() {}
13
14
    /*
15
     * @return void
16
     */
17
    protected function invokeTestSuite()
18
    {
19
        $monitor = $this->getMonitor();
20
        $globalConfig = $monitor->getGlobalConfig();
21
22
        // Check Memcache-servers
23
        $class = class_exists('Memcache') ? 'Memcache' : (class_exists('Memcached') ? 'Memcached' : false);
24
        if ($class === false) {
25
            $serverGroups = $globalConfig->getValue('memcache_store.servers');
26
            $serverGroupName = array_map(function($i) {
27
                $tmp = array_keys($i);
28
                return 'Server Group #' . ++$tmp[0];
29
            }, $serverGroups);
30
31
            $this->setState(State::FATAL);
32
            $this->addMessage(State::FATAL, 'Memcache health', implode(PHP_EOL, $serverGroupName), 'Missing PHP module');
33
            
34
        } else {
35
            $stats = SimpleSAML_Memcache::getRawStats();
36
37
            foreach ($stats as $key => $serverGroup) {
38
                $groupName = is_numeric($key) ? '#' . ++$key : "`$key'";
39
                $groupTests = array();
40
41
                foreach ($serverGroup as $host => $serverStats) {
42
                    $groupTests[] = new TestCase\Store\Memcache\Server($this, array('server_stats' => $serverStats, 'host' => $host));
43
                }
44
45
                $test = new TestCase\Store\Memcache\ServerGroup($this, array('tests' => $groupTests, 'group' => $groupName));
46
                $this->addTest($test);
47
            }
48
49
            $tests = $this->getTests();
50
            foreach ($tests as $serverGroup) {
51
                $this->addMessages($serverGroup->getMessages());
52
            }
53
        }
54
55
        $this->calculateState();
56
    }
57
}
58