Secure   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A protectDatas() 0 15 2
1
<?php
2
3
namespace BfwSql\Helpers;
4
5
use \Exception;
6
7
/**
8
 * Helpers to securize data
9
 */
10
class Secure
11
{
12
    const ERR_NO_DATABASE_CONNECTED = 2702001;
13
    
14
    /**
15
     * Protect datas with sql protect method
16
     * 
17
     * @param string $datas Datas to protect
18
     * 
19
     * @return string
20
     * 
21
     * @throw \Exception If no database connected
22
     */
23
    public static function protectDatas(string $datas): string
24
    {
25
        $dbModule = \BFW\Application::getInstance()
26
            ->getModuleList()
27
            ->getModuleByName('bfw-sql')
28
        ;
29
        
30
        if (count($dbModule->listBases) === 0) {
31
            throw new Exception(
32
                'No database connected to protect data',
33
                self::ERR_NO_DATABASE_CONNECTED
34
            );
35
        }
36
        
37
        return reset($dbModule->listBases)->protect($datas);
38
    }
39
}
40