Floating::stringify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Samshal\Rando\Packages\Basics;
4
5
use Samshal\Rando\Packages\PackageableInterface;
6
use Samshal\Rando\Packages\Packages;
7
8
class Floating extends Packages implements PackageableInterface
9
{
10
11
    protected $fixed;
12
    protected $min;
13
    protected $max;
14
15
    public function setDefaults($defaultsArray = [])
16
    {
17
        $defaultsArray['fixed'] = 4;
18
        $defaultsArray['min'] = 0;
19
        $defaultsArray['max'] = mt_getrandmax();
20
21
        return $defaultsArray;
22
    }
23
24
    protected function setFixed($fixed)
25
    {
26
        $this->fixed = $fixed;
27
    }
28
29
    protected function setMin($min)
30
    {
31
        $this->min = $min;
32
    }
33
34
    protected function setMax($max)
35
    {
36
        $this->max = $max;
37
    }
38
39
    private function generateDefaults()
40
    {
41
        if (empty($this->fixed)) {
42
            $this->fixed = $this->setDefaults()['fixed'];
43
        }
44
45
        if (empty($this->min)) {
46
            $this->min = $this->setDefaults()['min'];
47
        }
48
49
        if (empty($this->max)) {
50
            $this->max = $this->setDefaults()['max'];
51
        }
52
    }
53
    private function generateFloatNumber()
54
    {
55
        self::generateDefaults();
56
        
57
        $scale = pow(10, $this->fixed);
58
        return mt_rand($this->min, $this->max) / $scale;
59
    }
60
61
    public function stringify()
62
    {
63
        return self::generateFloatNumber();
64
    }
65
}
66