Completed
Push — master ( f7fb6b...e4d297 )
by Tony Karavasilev (Тони
15:27
created

getDerivationIterations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Trait implementation of the derivation control over the internal number of iterations for digestion algorithms.
5
 */
6
7
namespace CryptoManana\Core\Traits\MessageDigestion;
8
9
use \CryptoManana\Core\Interfaces\MessageDigestion\DerivationIterationControlInterface as IterationControlSpecification;
10
11
/**
12
 * Trait DerivationIterationControlTrait - Reusable implementation of `DerivationIterationControlInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\MessageDigestion\DerivationIterationControlInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\MessageDigestion
17
 *
18
 * @property int $numberOfIterations The derivation internal iteration count property storage.
19
 *
20
 * @mixin IterationControlSpecification
21
 */
22
trait DerivationIterationControlTrait
23
{
24
    /**
25
     * Setter for the derivation internal iteration count property.
26
     *
27
     * @param int $numberOfIterations The number of internal iterations to perform.
28
     *
29
     * @return $this The hash algorithm object.
30
     * @throws \Exception Validation errors.
31
     */
32
    public function setDerivationIterations($numberOfIterations)
33
    {
34
        $numberOfIterations = filter_var(
35
            $numberOfIterations,
36
            FILTER_VALIDATE_INT,
37
            [
38
                "options" => [
39
                    "min_range" => 1,
40
                    "max_range" => PHP_INT_MAX,
41
                ],
42
            ]
43
        );
44
45
        if ($numberOfIterations === false) {
46
            throw new \InvalidArgumentException(
47
                'The number of internal iterations must be a valid integer bigger than 0.'
48
            );
49
        }
50
51
        $this->numberOfIterations = $numberOfIterations;
52
53
        return $this;
54
    }
55
56
    /**
57
     * Getter for the derivation internal iteration count property.
58
     *
59
     * @return int The number of internal iterations to perform.
60
     */
61
    public function getDerivationIterations()
62
    {
63
        return $this->numberOfIterations;
64
    }
65
}
66