GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d9c1b5...e784c7 )
by Xaf
04:37 queued 02:56
created

Cups::generateRandomNumberWithRange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace CupsGenerator;
4
5
/**
6
 * Class to generate a random cups.
7
 */
8
class Cups
9
{
10
    /**
11
     * Cups id.
12
     *
13
     * @param $string
14
     */
15
    private $id;
16
17
    /**
18
     * Generate a Random cups.
19
     *
20
     * @return string
21
     */
22
    public function generate()
23
    {
24
        $reeId = $this->generateReeId();
25
        $distId = $this->generateDistId();
26
27
        $control = ($reeId.$distId) % 529;
28
        $division = $control / 23;
29
        $resto = $control % 23;
30
31
        $this->id = $this->getCountry()
32
            . $reeId
33
            . $distId
34
            . $this->getControlNumbersBy($division)
35
            . $this->getControlNumbersBy($resto);
36
37
        return $this->id;
38
    }
39
40
    /**
41
     * Genera los 4 numeros dados por la Red electrica de España
42
     *
43
     * @return string
44
     */
45
    private function generateReeId()
46
    {
47
        $random = mt_rand(0, 9999);
48
49
        return str_pad($random, 4, STR_PAD_LEFT);
50
    }
51
52
    /**
53
     * Genera los 12 numeros Id del distribuidor.
54
     *
55
     * @return string
56
     */
57
    private function generateDistId()
58
    {
59
        if (PHP_INT_SIZE == 4) {
60
            return $this->generateRandomNumberWithRange(9)
61
                . $this->generateRandomNumberWithRange(3);
62
        }
63
64
        return $this->generateRandomNumberWithRange(12);
65
    }
66
67
    /**
68
     * @param $range
69
     * @return string
70
     */
71
    private function generateRandomNumberWithRange($range)
72
    {
73
        $randomNumber = mt_rand(0, str_repeat("9", $range));
74
75
        return str_pad($randomNumber, $range, '0', STR_PAD_LEFT);
76
    }
77
78
    /**
79
     * Retorna ISO pais.
80
     *
81
     * @return string
82
     */
83
    private function getCountry()
84
    {
85
        return 'ES';
86
    }
87
88
    /**
89
     * Retorna array with control.
90
     *
91
     * @return array
92
     */
93
    private function getControlNumbers()
94
    {
95
        return [
96
            0  => 'T',
97
            1  => 'R',
98
            2  => 'W',
99
            3  => 'A',
100
            4  => 'G',
101
            5  => 'M',
102
            6  => 'Y',
103
            7  => 'F',
104
            8  => 'P',
105
            9  => 'D',
106
            10 => 'X',
107
            11 => 'B',
108
            12 => 'N',
109
            13 => 'J',
110
            14 => 'Z',
111
            15 => 'S',
112
            16 => 'Q',
113
            17 => 'V',
114
            18 => 'H',
115
            19 => 'L',
116
            20 => 'C',
117
            21 => 'K',
118
            22 => 'E',
119
        ];
120
    }
121
122
    /**
123
     * Return array with control.
124
     *
125
     * @return string
126
     */
127
    private function getControlNumbersBy($id)
128
    {
129
        $controlNumber = $this->getControlNumbers();
130
131
        return $controlNumber[$id];
132
    }
133
}
134