Completed
Push — master ( bec47f...d3ed9f )
by Tony Karavasilev (Тони
07:35
created

DigestionKeyTrait::setKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * Trait implementation of the keyed hashing capabilities for digestion algorithms.
5
 */
6
7
namespace CryptoManana\Core\Traits\MessageDigestion;
8
9
use \CryptoManana\Core\Interfaces\MessageDigestion\DigestionKeyInterface as DigestionKeySpecification;
10
11
/**
12
 * Trait DigestionKeyTrait - Reusable implementation of `DigestionKeyInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\MessageDigestion\DigestionKeyInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\MessageDigestion
17
 *
18
 * @property string $key The key string property storage.
19
 *
20
 * @mixin DigestionKeySpecification
21
 */
22
trait DigestionKeyTrait
23
{
24
    /**
25
     * Setter for the key string property.
26
     *
27
     * @param string $key The digestion key string.
28
     *
29
     * @return $this The hash algorithm object.
30
     * @throw \Exception Validation errors.
31
     */
32
    public function setKey($key)
33
    {
34
        if (!is_string($key)) {
1 ignored issue
show
introduced by
The condition is_string($key) is always true.
Loading history...
35
            throw new \InvalidArgumentException('The key must be of type string.');
36
        }
37
38
        $this->key = $key;
39
40
        return $this;
41
    }
42
43
    /**
44
     * Getter for the key string property.
45
     *
46
     * @return string The digestion key string.
47
     */
48
    public function getKey()
49
    {
50
        return $this->key;
51
    }
52
}
53