verifyOption()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
cc 6
eloc 11
nc 4
nop 3
1
<?php
2
/**
3
 * Private key path option.
4
 *
5
 * @package ThreemaGateway
6
 * @author rugk
7
 * @copyright Copyright (c) 2016 rugk
8
 * @license MIT
9
 */
10
11
class ThreemaGateway_Option_PhpKeyStorePath
12
{
13
    /**
14
     * Verifies the existence of the path.
15
     *
16
     * @param string             $phpKeystore Input
17
     * @param XenForo_DataWriter $dataWriter
18
     * @param string             $fieldName   Name of field/option
19
     *
20
     * @return bool
21
     */
22
    public static function verifyOption(&$phpKeystore, XenForo_DataWriter $dataWriter, $fieldName)
23
    {
24
        if (!$phpKeystore || !$phpKeystore['enabled']) {
25
            // skip check if PHP keystore is not enabled
26
            return true;
27
        }
28
29
        // check existence
30
        if (pathinfo($phpKeystore['path'], PATHINFO_EXTENSION) != 'php' ||
31
            !file_exists(__DIR__ . '/../' . $phpKeystore['path'])
32
        ) {
33
            $dataWriter->error(new XenForo_Phrase('threemagw_invalid_keystorepath'), $fieldName);
34
            return false;
35
        }
36
37
        // check whether it is writable
38
        if (!is_writable(__DIR__ . '/../' . $phpKeystore['path'])) {
39
            $dataWriter->error(new XenForo_Phrase('threemagw_not_writable_keystorefile'), $fieldName);
40
            return false;
41
        }
42
43
        return true;
44
    }
45
}
46