Completed
Pull Request — master (#2)
by Milos
04:36
created

FallbackRandomGenerator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 74
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getFirst() 0 4 1
A setFirst() 0 6 1
A getSecond() 0 4 1
A setSecond() 0 6 1
A get() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the tmilos/jose-jwt package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\JoseJwt\Random;
13
14
use Tmilos\JoseJwt\Error\JoseJwtException;
15
16
class FallbackRandomGenerator implements RandomGenerator
17
{
18
    /** @var RandomGenerator|null */
19
    private $first;
20
21
    /** @var RandomGenerator|null */
22
    private $second;
23
24
    /**
25
     * @param RandomGenerator $first
26
     * @param RandomGenerator $second
27
     */
28
    public function __construct(RandomGenerator $first = null, RandomGenerator $second = null)
29
    {
30
        $this->first = $first;
31
        $this->second = $second;
32
    }
33
34
    /**
35
     * @return RandomGenerator|null
36
     */
37
    public function getFirst()
38
    {
39
        return $this->first;
40
    }
41
42
    /**
43
     * @param RandomGenerator|null $first
44
     *
45
     * @return FallbackRandomGenerator
46
     */
47
    public function setFirst(RandomGenerator $first = null)
48
    {
49
        $this->first = $first;
50
51
        return $this;
52
    }
53
54
    /**
55
     * @return RandomGenerator|null
56
     */
57
    public function getSecond()
58
    {
59
        return $this->second;
60
    }
61
62
    /**
63
     * @param RandomGenerator|null $second
64
     *
65
     * @return FallbackRandomGenerator
66
     */
67
    public function setSecond(RandomGenerator $second = null)
68
    {
69
        $this->second = $second;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @param int $bytesLength
76
     *
77
     * @return string
78
     */
79
    public function get($bytesLength)
80
    {
81
        if ($this->first) {
82
            return $this->first->get($bytesLength);
83
        } elseif ($this->second) {
84
            return $this->second->get($bytesLength);
85
        }
86
87
        throw new JoseJwtException('No random generators provided');
88
    }
89
}
90