Integer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 46
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setDefaults() 0 7 1
A setMin() 0 4 1
A setMax() 0 4 1
A generateInteger() 0 6 1
A stringify() 0 4 1
A generateDefaults() 0 10 3
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 Integer extends Packages implements PackageableInterface
9
{
10
11
    protected $min;
12
    protected $max;
13
14
    public function setDefaults($defaultsArray = [])
15
    {
16
        $defaultsArray['min'] = -1 * mt_getrandmax();
17
        $defaultsArray['max'] = mt_getrandmax();
18
19
        return $defaultsArray;
20
    }
21
22
    protected function setMin($min)
23
    {
24
        $this->min = $min;
25
    }
26
27
    protected function setMax($max)
28
    {
29
        $this->max = $max;
30
    }
31
32
    private function generateDefaults()
33
    {
34
        if (empty($this->min)) {
35
            self::setMin($this->setDefaults()['min']);
36
        }
37
38
        if (empty($this->max)) {
39
            self::setMax($this->max = $this->setDefaults()['max']);
40
        }
41
    }
42
    private function generateInteger()
43
    {
44
        self::generateDefaults();
45
46
        return mt_rand($this->min, $this->max);
47
    }
48
49
    public function stringify()
50
    {
51
        return self::generateInteger();
52
    }
53
}
54