Completed
Push — master ( 58f651...10b3db )
by Tony Karavasilev (Тони
06:27
created

AbstractHashAlgorithm::addSaltString()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 35
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 31
CRAP Score 10

Importance

Changes 0
Metric Value
eloc 31
c 0
b 0
f 0
dl 0
loc 35
ccs 31
cts 31
cp 1
rs 7.6666
cc 10
nc 10
nop 1
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * The hash algorithm abstraction specification.
5
 */
6
7
namespace CryptoManana\Core\Abstractions\MessageDigestion;
8
9
use \CryptoManana\Core\Interfaces\MessageDigestion\SaltingCapabilitiesInterface as DataSalting;
10
use \CryptoManana\Core\Interfaces\MessageDigestion\DigestionFormatsInterface as DigestFormatting;
11
use \CryptoManana\Core\Traits\MessageDigestion\SaltingCapabilitiesTrait as SaltingCapabilities;
12
use \CryptoManana\Core\Traits\MessageDigestion\DigestionFormatsTrait as DigestOutputFormats;
13
14
/**
15
 * Class AbstractHashAlgorithm - The hash algorithm abstraction representation.
16
 *
17
 * @package CryptoManana\Core\Abstractions\MessageDigestion
18
 *
19
 * @mixin SaltingCapabilities
20
 * @mixin DigestOutputFormats
21
 */
22
abstract class AbstractHashAlgorithm implements DataSalting, DigestFormatting
23
{
24
    /**
25
     * Data salting capabilities.
26
     *
27
     * {@internal Reusable implementation of `SaltingCapabilitiesInterface`. }}
28
     */
29
    use SaltingCapabilities;
30
31
    /**
32
     * Digest outputting formats.
33
     *
34
     * {@internal Reusable implementation of `DigestionFormatsInterface`. }}
35
     */
36
    use DigestOutputFormats;
37
38
    /**
39
     * The salt string property storage.
40
     *
41
     * @var string The salting string value.
42
     */
43
    protected $salt = '';
44
45
    /**
46
     * The salting mode property storage.
47
     *
48
     * @var int The salting mode integer code value.
49
     */
50
    protected $saltingMode = self::SALTING_MODE_APPEND;
51
52
    /**
53
     * The digest output format property storage.
54
     *
55
     * @var int The output format integer code value.
56
     */
57
    protected $digestFormat = self::DIGEST_OUTPUT_HEX_UPPER;
58
59
    /**
60
     * Hash algorithm constructor.
61
     */
62
    abstract public function __construct();
63
64
    /**
65
     * Calculates a hash value for the given data.
66
     *
67
     * @param string $data The input string.
68
     *
69
     * @return string The digest.
70
     * @throws \Exception Validation errors.
71
     */
72
    abstract public function hashData($data);
73
}
74