Passed
Push — master ( 151dda...f1e0bb )
by Vince
01:47
created

help::checkVal()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 4
c 1
b 0
f 1
nc 4
nop 3
dl 0
loc 9
rs 10
1
<?php
2
/**
3
 * ==================================
4
 * Responsible PHP API
5
 * ==================================
6
 *
7
 * @link Git https://github.com/vince-scarpa/responsibleAPI.git
8
 *
9
 * @api Responible API
10
 * @package responsible\core\exception
11
 *
12
 * @author Vince scarpa <[email protected]>
13
 *
14
 */
15
namespace responsible\core\helpers;
16
17
class help
18
{
19
    /**
20
     * INJECTION SANITIZER
21
     * @return: SANITIZED STRING
22
     */
23
    public function Sanitize($str, $remove_nl = true)
24
    {
25
        if (($str == '')) {
26
            return '';
27
        }
28
29
        $str = stripslashes($str);
30
31
        if ($remove_nl) {
32
            $injections = array(
33
                '/(\n+)/i',
34
                '/(\r+)/i',
35
                '/(\t+)/i',
36
                '/(%0A+)/i',
37
                '/(%0D+)/i',
38
                '/(%08+)/i',
39
                '/(%09+)/i',
40
            );
41
42
            $str = preg_replace($injections, '', $str);
43
        }
44
45
        return $str;
46
    }
47
48
49
    /**
50
     * [getClaim Check if a claim is set and not empty]
51
     * @param  string $claim
52
     * @return mixed
53
     */
54
    public function checkVal($option, $key, $default = false)
55
    {
56
        $val = isset($option[$key]) ? $option[$key] : $default;
57
58
        if ($val && empty($option[$key])) {
59
            $val = $default;
60
        }
61
62
        return $val;
63
    }
64
}
65