Skip to content

Commit b9a2377

Browse files
committed
Improve variable names
1 parent 871daeb commit b9a2377

File tree

4 files changed

+55
-55
lines changed

4 files changed

+55
-55
lines changed

src/Types/TypeCode11.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,27 @@ public function getBarcode(string $code): Barcode
6060

6161
private function getCheckDigitC(string $code): string
6262
{
63-
$p = 1;
64-
$check = 0;
63+
$weight = 1;
64+
$checksum = 0;
6565
for ($i = (strlen($code) - 1); $i >= 0; --$i) {
6666
$digit = $code[$i];
6767
if ($digit == '-') {
68-
$dval = 10;
68+
$digitValue = 10;
6969
} else {
70-
$dval = intval($digit);
70+
$digitValue = intval($digit);
7171
}
72-
$check += ($dval * $p);
73-
++$p;
74-
if ($p > 10) {
75-
$p = 1;
72+
$checksum += ($digitValue * $weight);
73+
++$weight;
74+
if ($weight > 10) {
75+
$weight = 1;
7676
}
7777
}
78-
$check %= 11;
79-
if ($check == 10) {
80-
$check = '-';
78+
$checksum %= 11;
79+
if ($checksum == 10) {
80+
$checksum = '-';
8181
}
8282

83-
return $check;
83+
return $checksum;
8484
}
8585

8686
private function getCheckDigitK(string $code): string
@@ -89,23 +89,23 @@ private function getCheckDigitK(string $code): string
8989
return '';
9090
}
9191

92-
$p = 1;
93-
$check = 0;
92+
$weight = 1;
93+
$checksum = 0;
9494
for ($i = (strlen($code) - 1); $i >= 0; --$i) {
9595
$digit = $code[$i];
9696
if ($digit == '-') {
97-
$dval = 10;
97+
$digitValue = 10;
9898
} else {
99-
$dval = intval($digit);
99+
$digitValue = intval($digit);
100100
}
101-
$check += ($dval * $p);
102-
++$p;
103-
if ($p > 9) {
104-
$p = 1;
101+
$checksum += ($digitValue * $weight);
102+
++$weight;
103+
if ($weight > 9) {
104+
$weight = 1;
105105
}
106106
}
107-
$check %= 11;
107+
$checksum %= 11;
108108

109-
return (string)$check;
109+
return (string)$checksum;
110110
}
111111
}

src/Types/TypeCode32.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ public function getBarcode(string $code): Barcode
9898
*/
9999
protected function checksum_code32(string $code): string
100100
{
101-
$s = 0;
101+
$checksum = 0;
102102

103103
foreach (str_split($code) as $i => $c) {
104104
if (0 === $i % 2) {
105-
$s += (int)$c;
105+
$checksum += (int)$c;
106106
} else {
107107
$c = 2 * (int)$c;
108-
$s += (int)floor($c / 10) + ($c % 10);
108+
$checksum += (int)floor($c / 10) + ($c % 10);
109109
}
110110
}
111111

112-
return (string)($s % 10);
112+
return (string)($checksum % 10);
113113
}
114114
}

src/Types/TypeCode39.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,13 @@ protected function checksum_code39($code)
318318
'%'
319319
];
320320

321-
$sum = 0;
322-
for ($i = 0; $i < strlen($code); ++$i) {
323-
$k = array_keys($chars, $code[$i]);
324-
$sum += $k[0];
321+
$checksum = 0;
322+
for ($index = 0; $index < strlen($code); ++$index) {
323+
$charPosition = array_keys($chars, $code[$index]);
324+
$checksum += $charPosition[0];
325325
}
326-
$j = ($sum % 43);
326+
$checksumIndex = ($checksum % 43);
327327

328-
return $chars[$j];
328+
return $chars[$checksumIndex];
329329
}
330330
}

src/Types/TypeCode93.php

+23-23
Original file line numberDiff line numberDiff line change
@@ -251,35 +251,35 @@ protected function checksum_code93(string $code): string
251251
$chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '-', '.', ' ', '$', '/', '+', '%', 'a', 'b', 'c', 'd'];
252252

253253
// calculate check digit C
254-
$len = strlen($code);
255-
$p = 1;
256-
$check = 0;
257-
for ($i = ($len - 1); $i >= 0; --$i) {
258-
$k = array_keys($chars, $code[$i]);
259-
$check += ($k[0] * $p);
260-
++$p;
261-
if ($p > 20) {
262-
$p = 1;
254+
$codeLength = strlen($code);
255+
$weight = 1;
256+
$checksum = 0;
257+
for ($i = ($codeLength - 1); $i >= 0; --$i) {
258+
$charIndex = array_keys($chars, $code[$i]);
259+
$checksum += ($charIndex[0] * $weight);
260+
++$weight;
261+
if ($weight > 20) {
262+
$weight = 1;
263263
}
264264
}
265-
$check %= 47;
266-
$c = $chars[$check];
267-
$code .= $c;
265+
$checksumC = $checksum % 47;
266+
$checkDigitC = $chars[$checksumC];
267+
$codeWithC = $code . $checkDigitC;
268268

269269
// calculate check digit K
270-
$p = 1;
271-
$check = 0;
272-
for ($i = $len; $i >= 0; --$i) {
273-
$k = array_keys($chars, $code[$i]);
274-
$check += ($k[0] * $p);
275-
++$p;
276-
if ($p > 15) {
277-
$p = 1;
270+
$weight = 1;
271+
$checksum = 0;
272+
for ($i = $codeLength; $i >= 0; --$i) {
273+
$charIndex = array_keys($chars, $codeWithC[$i]);
274+
$checksum += ($charIndex[0] * $weight);
275+
++$weight;
276+
if ($weight > 15) {
277+
$weight = 1;
278278
}
279279
}
280-
$check %= 47;
281-
$k = $chars[$check];
280+
$checksumK = $checksum % 47;
281+
$checkDigitK = $chars[$checksumK];
282282

283-
return $c . $k;
283+
return $checkDigitC . $checkDigitK;
284284
}
285285
}

0 commit comments

Comments
 (0)