Safe   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
c 2
b 1
f 0
lcom 1
cbo 0
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A encrypt() 0 4 1
A decrypt() 0 4 1
A hashEncode() 0 4 1
A secure() 0 17 4
1
<?php
2
/**
3
 * User: Sephy
4
 * Date: 06/06/2016
5
 * Time: 04:25.
6
 */
7
namespace Core\Helpers;
8
9
class Safe
10
{
11
    public static $salt = 'tfju=fiM148We4oYuyojjzmA6b9UKGhQ';
12
13
    /**
14
     * @param $text
15
     *
16
     * @return string
17
     */
18
    public static function encrypt($text)
19
    {
20
        return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, self::$salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND))));
21
    }
22
23
    /**
24
     * @param $text
25
     *
26
     * @return string
27
     */
28
    public static function decrypt($text)
29
    {
30
        return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, self::$salt, base64_decode($text), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND)));
31
    }
32
33
    /**
34
     * @param $value
35
     *
36
     * @return bool|string
37
     */
38
    public static function hashEncode($value)
39
    {
40
        return password_hash($value, PASSWORD_DEFAULT);
41
    }
42
43
    /**
44
     * @param $array
45
     */
46
    public static function secure(&$array)
47
    {
48
        if (isset($array)) {
49
            foreach ($array as $key => $value) {
50
                if (is_array($array[$key])) {
51
                    self::secure($array[$key]);
52
                } else {
53
                    $array[$key] = trim($array[$key]);
54
                    $array[$key] = htmlspecialchars($array[$key], ENT_QUOTES, 'UTF-8');
55
                    $array[$key] = strip_tags($array[$key]);
56
                    $array[$key] = addslashes($array[$key]);
57
                    $array[$key] = filter_var($array[$key], FILTER_SANITIZE_STRING);
58
                    $array[$key] = html_entity_decode($array[$key], ENT_COMPAT, 'UTF-8');
59
                }
60
            }
61
        }
62
    }
63
}
64