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 ( be7e28...6f5fe5 )
by Xaf
9s
created

Cups::getControlNumbers()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 25
nc 1
nop 0
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
     * @todo improve this for
44
     *
45
     * @return string
46
     */
47
    private function generateReeId()
48
    {
49
        $id = mt_rand(0, 9999);
50
51
        for ($idLength = strlen($id); $idLength < 4; $idLength++) {
52
            $id = '0' . $id;
53
        }
54
55
        return $id;
56
    }
57
58
    /**
59
     * Genera los 12 numeros Id del distribuidor.
60
     *
61
     * @todo improve this for
62
     *
63
     * @return string
64
     */
65
    private function generateDistId()
66
    {
67
        if (PHP_INT_SIZE == 4) {
68
            $random = mt_rand(0, 999999999);
69
            $id = str_pad($random, 9, '0', STR_PAD_LEFT);
70
            $random = mt_rand(0, 999);
71
            $id .= str_pad($random, 3, '0', STR_PAD_LEFT);
72
        } else {
73
            $random = mt_rand(0, 999999999999);
74
            $id = str_pad($random, 12, '0', STR_PAD_LEFT);
75
        }
76
77
        return $id;
78
    }
79
80
    /**
81
     * Retorna ISO pais.
82
     *
83
     * @return string
84
     */
85
    private function getCountry()
86
    {
87
        return 'ES';
88
    }
89
90
    /**
91
     * Retorna array with control.
92
     *
93
     * @return array
94
     */
95
    private function getControlNumbers()
96
    {
97
        return [
98
            0  => 'T',
99
            1  => 'R',
100
            2  => 'W',
101
            3  => 'A',
102
            4  => 'G',
103
            5  => 'M',
104
            6  => 'Y',
105
            7  => 'F',
106
            8  => 'P',
107
            9  => 'D',
108
            10 => 'X',
109
            11 => 'B',
110
            12 => 'N',
111
            13 => 'J',
112
            14 => 'Z',
113
            15 => 'S',
114
            16 => 'Q',
115
            17 => 'V',
116
            18 => 'H',
117
            19 => 'L',
118
            20 => 'C',
119
            21 => 'K',
120
            22 => 'E',
121
        ];
122
    }
123
124
    /**
125
     * Retorna array with control.
126
     *
127
     * @todo improve the return
128
     *
129
     * @return string
130
     */
131
    private function getControlNumbersBy($id)
132
    {
133
        $controlNumber = $this->getControlNumbers();
134
135
        return $controlNumber[(int) $id];
136
    }
137
}
138