consentSimpleAdmin_hook_sanitycheck()   A
last analyzed

Complexity

Conditions 4
Paths 9

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 2
b 0
f 0
nc 9
nop 1
dl 0
loc 23
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
use Exception;
6
use SimpleSAML\Assert\Assert;
7
use SimpleSAML\Configuration;
8
use SimpleSAML\Module\consent\Store;
9
10
use function is_callable;
11
12
/**
13
 * @param array &$hookinfo  hookinfo
14
 */
15
function consentSimpleAdmin_hook_sanitycheck(array &$hookinfo): void
16
{
17
    Assert::keyExists($hookinfo, 'errors');
18
    Assert::keyExists($hookinfo, 'info');
19
20
    try {
21
        $consentconfig = Configuration::getConfig('module_consentSimpleAdmin.php');
22
23
        // Parse consent config
24
        $consent_storage = Store::parseStoreConfig($consentconfig->getValue('store'));
25
26
        if (!is_callable([$consent_storage, 'selftest'])) {
27
            // Doesn't support a selftest
28
            return;
29
        }
30
        $testres = $consent_storage->selftest();
0 ignored issues
show
Bug introduced by
The method selftest() does not exist on SimpleSAML\Module\consent\Store. It seems like you code against a sub-type of SimpleSAML\Module\consent\Store such as SimpleSAML\Module\consent\Consent\Store\Database. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        /** @scrutinizer ignore-call */ 
31
        $testres = $consent_storage->selftest();
Loading history...
31
        if ($testres) {
32
            $hookinfo['info'][] = '[consentSimpleAdmin] Consent Storage selftest OK.';
33
        } else {
34
            $hookinfo['errors'][] = '[consentSimpleAdmin] Consent Storage selftest failed.';
35
        }
36
    } catch (Exception $e) {
37
        $hookinfo['errors'][] = '[consentSimpleAdmin] Error connecting to storage: ' . $e->getMessage();
38
    }
39
}
40