Completed
Push — master ( 1eed51...38666c )
by Tony Karavasilev (Тони
04:53 queued 02:00
created

RandomnessInjectableTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 30
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setRandomGenerator() 0 7 2
A getRandomGenerator() 0 3 1
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 1
    public function setRandomGenerator(RandomnessSource $generator)
30
    {
31 1
        if (!is_null($generator)) {
32 1
            $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 1
        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 1
    public function getRandomGenerator()
46
    {
47 1
        return $this->randomnessSource;
48
    }
49
}
50