IntegerGenerator::end()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PragmaRX\Random\Generators;
4
5
trait IntegerGenerator
6
{
7
    protected $start = 0;
8
9
    protected $end = PHP_INT_MAX;
10
11
    /**
12
     * Set numeric end.
13
     *
14
     * @param int $end
15
     * @return $this
16
     */
17 1
    public function end($end)
18
    {
19 1
        $this->end = $end;
20
21 1
        return $this;
22
    }
23
24
    /**
25
     * Generate a random integer.
26
     *
27
     * @return int
28
     */
29 1
    protected function generateInteger()
30
    {
31 1
        return $this->generateRandomInt($this->getStart(), $this->getEnd());
32
    }
33
34
    /**
35
     * Generate a random integer.
36
     *
37
     * @param int $start
38
     * @param int $end
39
     * @return int
40
     */
41 2
    protected function generateRandomInt($start, $end)
42
    {
43 2
        return random_int($start, $end);
44
    }
45
46
    /**
47
     * Get numeric end.
48
     *
49
     * @return int
50
     */
51 1
    public function getEnd()
52
    {
53 1
        return $this->end;
54
    }
55
56
    /**
57
     * Get numeric start.
58
     *
59
     * @return int
60
     */
61 1
    public function getStart()
62
    {
63 1
        return $this->start;
64
    }
65
66
    /**
67
     * Set numeric start.
68
     *
69
     * @param int $start
70
     * @return $this
71
     */
72 1
    public function start($start)
73
    {
74 1
        $this->start = $start;
75
76 1
        return $this;
77
    }
78
}
79