Passed
Push — master ( a24d5d...5d2fe9 )
by Julien
05:02
created

Security   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 10
c 1
b 0
f 1
dl 0
loc 20
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfig() 0 3 1
A hash() 0 13 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Encryption;
13
14
use Phalcon\Encryption\Security as PhalconSecurity;
15
use Zemit\Config\ConfigInterface;
16
17
/**
18
 * {@inheritDoc}
19
 */
20
class Security extends PhalconSecurity
21
{
22
    public function getConfig(): ConfigInterface
23
    {
24
        return $this->getDI()->get('config');
25
    }
26
    
27
    public function hash(string $password, array $options = []) : string
28
    {
29
        if (in_array($this->getDefaultHash(), [
30
            PhalconSecurity::CRYPT_ARGON2I,
31
            PhalconSecurity::CRYPT_ARGON2ID
32
        ])) {
33
            $defaultOptions = $this->getConfig()->pathToArray('security.argon2');
34
            $options['memory_cost'] ??= $defaultOptions['memoryCost'];
35
            $options['time_cost'] ??= $defaultOptions['timeCost'];
36
            $options['threads'] ??= $defaultOptions['threads'];
37
        }
38
        
39
        return parent::hash($password, $options);
40
    }
41
}
42