Completed
Push — master ( e4d297...14927f )
by Tony Karavasilev (Тони
16:15
created

AlgorithmicCostTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setAlgorithmicCost() 0 22 2
A getAlgorithmicCost() 0 3 1
1
<?php
2
3
/**
4
 * Trait implementation of the total algorithmic cost tuning per one computation for digestion algorithms.
5
 */
6
7
namespace CryptoManana\Core\Traits\MessageDigestion;
8
9
use \CryptoManana\Core\Interfaces\MessageDigestion\AlgorithmicCostInterface as AlgorithmicCostSpecification;
10
11
/**
12
 * Trait AlgorithmicCostTrait - Reusable implementation of `AlgorithmicCostInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\MessageDigestion\AlgorithmicCostInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\MessageDigestion
17
 *
18
 * @property int $computationalCost The digestion internal computational cost property storage.
19
 *
20
 * @mixin AlgorithmicCostSpecification
21
 */
22
trait AlgorithmicCostTrait
23
{
24
    /**
25
     * Setter for the computational cost property.
26
     *
27
     * @param int $cost The algorithmic cost.
28
     *
29
     * @return $this The hash algorithm object.
30
     * @throws \Exception Validation errors.
31
     */
32 32
    public function setAlgorithmicCost($cost)
33
    {
34 32
        $cost = filter_var(
35 32
            $cost,
36 32
            FILTER_VALIDATE_INT,
37
            [
38
                "options" => [
39 32
                    "min_range" => static::MINIMUM_ALGORITHMIC_COST,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...INIMUM_ALGORITHMIC_COST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
40 32
                    "max_range" => static::MAXIMUM_ALGORITHMIC_COST,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...AXIMUM_ALGORITHMIC_COST was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
                ],
42
            ]
43
        );
44
45 32
        if ($cost === false) {
46 2
            throw new \InvalidArgumentException(
47 2
                'The number of internal iterations must be a valid integer bigger than 0.'
48
            );
49
        }
50
51 32
        $this->computationalCost = $cost;
52
53 32
        return $this;
54
    }
55
56
    /**
57
     * Getter for the computational cost property.
58
     *
59
     * @return int The algorithmic cost.
60
     */
61 2
    public function getAlgorithmicCost()
62
    {
63 2
        return $this->computationalCost;
64
    }
65
}
66