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.

Cups::generate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 11
cts 11
cp 1
rs 9.4285
cc 1
eloc 12
nc 1
nop 0
crap 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 1
    public function generate()
23
    {
24 1
        $reeId = $this->generateReeId();
25 1
        $distId = $this->generateDistId();
26
27 1
        $control = ($reeId.$distId) % 529;
28 1
        $division = $control / 23;
29 1
        $mod = $control % 23;
30
31 1
        $this->id = $this->getCountry()
32
            .$reeId
33 1
            .$distId
34 1
            .$this->getControlNumbersBy($division)
35 1
            .$this->getControlNumbersBy($mod);
36
37 1
        return $this->id;
38
    }
39
40
    /**
41
     * Generate the 4 numbers given by the Red electrica from España.
42
     *
43
     * @return string
44
     */
45 1
    private function generateReeId()
46
    {
47 1
        $random = mt_rand(0, 9999);
48
49 1
        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 1
    private function generateDistId()
58
    {
59 1
        if (PHP_INT_SIZE == 4) {
60
            return $this->generateRandomNumberWithRange(9)
61
                .$this->generateRandomNumberWithRange(3);
62
        }
63
64 1
        return $this->generateRandomNumberWithRange(12);
65
    }
66
67
    /**
68
     * @param $range
69
     *
70
     * @return string
71
     */
72 1
    private function generateRandomNumberWithRange($range)
73
    {
74 1
        $randomNumber = mt_rand(0, str_repeat('9', $range));
75
76 1
        return str_pad($randomNumber, $range, '0', STR_PAD_LEFT);
77
    }
78
79
    /**
80
     * Returns the country code.
81
     *
82
     * @return string
83
     */
84 1
    private function getCountry()
85
    {
86 1
        return 'ES';
87
    }
88
89
    /**
90
     * Returns an array with control Digit.
91
     *
92
     * @return array
93
     */
94 1
    private function getControlNumbers()
95
    {
96
        return [
97 1
            'T',
98 1
            'R',
99 1
            'W',
100 1
            'A',
101 1
            'G',
102 1
            'M',
103 1
            'Y',
104 1
            'F',
105 1
            'P',
106 1
            'D',
107 1
            'X',
108 1
            'B',
109 1
            'N',
110 1
            'J',
111 1
            'Z',
112 1
            'S',
113 1
            'Q',
114 1
            'V',
115 1
            'H',
116 1
            'L',
117 1
            'C',
118 1
            'K',
119 1
            'E',
120 1
        ];
121
    }
122
123
    /**
124
     * Return array with control.
125
     *
126
     * @param $id
127
     *
128
     * @return string
129
     */
130 1
    private function getControlNumbersBy($id)
131
    {
132 1
        $controlNumber = $this->getControlNumbers();
133
134 1
        return $controlNumber[$id];
135
    }
136
}
137