Passed
Push — master ( 1ad852...df2cff )
by Tim
07:55
created

memcacheMonitor_hook_sanitycheck()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
c 1
b 0
f 0
nc 9
nop 1
dl 0
loc 24
rs 9.2222
1
<?php
2
3
use Webmozart\Assert\Assert;
4
5
/**
6
 * Sanity check for memcache servers.
7
 *
8
 * This function verifies that all memcache servers work.
9
 *
10
 * @param array &$hookinfo  hookinfo
11
 */
12
function memcacheMonitor_hook_sanitycheck(array &$hookinfo): void
13
{
14
    Assert::keyExists($hookinfo, 'errors');
15
    Assert::keyExists($hookinfo, 'info');
16
17
    try {
18
        $servers = \SimpleSAML\Memcache::getRawStats();
19
    } catch (\Exception $e) {
20
        $hookinfo['errors'][] = '[memcacheMonitor] Error parsing memcache configuration: ' . $e->getMessage();
21
        return;
22
    }
23
24
    $allOK = true;
25
    foreach ($servers as $group) {
26
        foreach ($group as $server => $status) {
27
            if ($status === false) {
28
                $hookinfo['errors'][] = '[memcacheMonitor] No response from server: ' . $server;
29
                $allOK = false;
30
            }
31
        }
32
    }
33
34
    if ($allOK) {
35
        $hookinfo['info'][] = '[memcacheMonitor] All servers responding.';
36
    }
37
}
38