Passed
Push — master ( d7488c...1eed51 )
by Tony Karavasilev (Тони
04:25
created

RandomnessInjectableTrait::setRandomGenerator()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 6
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Trait implementation of the setter dependency injection type for pseudo-random generator services.
5
 */
6
7
namespace CryptoManana\Core\Traits\Containers;
8
9
use \CryptoManana\Core\Abstractions\Randomness\AbstractGenerator as RandomnessSource;
10
11
/**
12
 * Trait RandomnessInjectableTrait - Reusable implementation of `RandomnessInjectableInterface`.
13
 *
14
 * @see \CryptoManana\Core\Interfaces\Containers\RandomnessInjectableInterface The abstract specification.
15
 *
16
 * @package CryptoManana\Core\Traits\Containers
17
 */
18
trait RandomnessInjectableTrait
19
{
20
    /**
21
     * Setter for the pseudo-random generator service.
22
     *
23
     * @see \CryptoManana\Core\Interfaces\Containers\RandomnessInjectableInterface::setRandomGenerator() Specification.
24
     *
25
     * @param RandomnessSource|null $generator The pseudo-random generator service.
26
     *
27
     * @return $this The container object.
28
     */
29
    public function setRandomGenerator(RandomnessSource $generator)
30
    {
31
        if (!is_null($generator)) {
32
            $this->randomnessSource = $generator;
0 ignored issues
show
Bug Best Practice introduced by
The property randomnessSource does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
        }
34
35
        return $this;
36
    }
37
38
    /**
39
     * Getter for the pseudo-random generator service.
40
     *
41
     * @see \CryptoManana\Core\Interfaces\Containers\RandomnessInjectableInterface::getRandomGenerator() Specification.
42
     *
43
     * @return RandomnessSource The currently injected pseudo-random generator service.
44
     */
45
    public function getRandomGenerator()
46
    {
47
        return $this->randomnessSource;
48
    }
49
}
50