Completed
Push — master ( 9083d4...b91f33 )
by Tony Karavasilev (Тони
11:46
created

DerivationDigestLengthTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setOutputLength() 0 23 2
A getOutputLength() 0 3 1
1
<?php
2
3
/**
4
 * Trait implementation of the derivation control over the outputting digest length for digestion algorithms.
5
 */
6
7
namespace CryptoManana\Core\Traits\MessageDigestion;
8
9
use \CryptoManana\Core\Interfaces\MessageDigestion\DerivationDigestLengthInterface as DigestLengthSpecification;
10
11
/**
12
 * Trait DerivationDigestLengthTrait - Reusable implementation of `DerivationDigestLengthInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\MessageDigestion\DerivationDigestLengthInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\MessageDigestion
17
 *
18
 * @property string $outputLength The derivation output digest size in bytes length property storage.
19
 *
20
 * @mixin DigestLengthSpecification
21
 */
22
trait DerivationDigestLengthTrait
23
{
24
    /**
25
     * Setter for the derivation output digest size in bytes length property.
26
     *
27
     * @param int $byteLength The derivation output digest size in bytes length.
28
     *
29
     * @return $this The hash algorithm object.
30
     * @throw \Exception Validation errors.
31
     */
32 66
    public function setOutputLength($byteLength)
33
    {
34 66
        $byteLength = filter_var(
35 66
            $byteLength,
36 66
            FILTER_VALIDATE_INT,
37
            [
38
                "options" => [
39 66
                    "min_range" => 1,
40 66
                    "max_range" => static::ALGORITHM_MAXIMUM_OUTPUT,
1 ignored issue
show
Bug introduced by
The constant CryptoManana\Core\Traits...LGORITHM_MAXIMUM_OUTPUT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
                ],
42
            ]
43
        );
44
45 66
        if ($byteLength === false) {
46 22
            throw new \InvalidArgumentException(
47
                'The output length must be a valid integer and be between 1 and ' .
48 22
                static::ALGORITHM_MAXIMUM_OUTPUT . '.'
49
            );
50
        }
51
52 44
        $this->outputLength = $byteLength;
53
54 44
        return $this;
55
    }
56
57
    /**
58
     * Getter for the derivation output digest size in bytes length property.
59
     *
60
     * @return int The derivation output digest size in bytes length.
61
     */
62 44
    public function getOutputLength()
63
    {
64 44
        return $this->outputLength;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->outputLength returns the type string which is incompatible with the documented return type integer.
Loading history...
65
    }
66
}
67