Skip to content

Commit

Permalink
Refactor array search logic for support php 8.4.
Browse files Browse the repository at this point in the history
Replaces direct `array_keys` usage with `array_filter` and closures for more explicit condition checks. Simplifies a specific case using `array_search` to enhance code clarity and maintainability. No functional changes introduced.
  • Loading branch information
AviMoto committed Dec 25, 2024
1 parent 14ffa0e commit 19dae55
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion tcpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -5562,7 +5562,9 @@ protected function getCellCode($w, $h=0, $txt='', $border=0, $ln=0, $align='', $
// x space to skip
if ($spacewidth != 0) {
// justification shift
$xshift += (count(array_keys($uniarr, 32)) * $spw);
$xshift += (count(array_keys(array_filter($uniarr, function ($element) {
return $element == 32;
}))) * $spw);
}
$xshift += $this->GetArrStringWidth($uniarr); // + shift justification
} else {
Expand Down
17 changes: 11 additions & 6 deletions tcpdf_barcodes_1d.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,9 @@ protected function checksum_code39($code) {
$sum = 0;
$clen = strlen($code);
for ($i = 0 ; $i < $clen; ++$i) {
$k = array_keys($chars, $code[$i]);
$k = array_keys(array_filter($chars, function ($value) use ($code, $i) {
return $value == $code[$i];
}));
$sum += $k[0];
}
$j = ($sum % 43);
Expand Down Expand Up @@ -699,7 +701,9 @@ protected function checksum_code93($code) {
$p = 1;
$check = 0;
for ($i = ($len - 1); $i >= 0; --$i) {
$k = array_keys($chars, $code[$i]);
$k = array_keys(array_filter($chars, function ($value) use ($code, $i) {
return $value == $code[$i];
}));
$check += ($k[0] * $p);
++$p;
if ($p > 20) {
Expand All @@ -713,7 +717,9 @@ protected function checksum_code93($code) {
$p = 1;
$check = 0;
for ($i = $len; $i >= 0; --$i) {
$k = array_keys($chars, $code[$i]);
$k = array_keys(array_filter($chars, function ($value) use ($code, $i) {
return $value == $code[$i];
}));
$check += ($k[0] * $p);
++$p;
if ($p > 15) {
Expand Down Expand Up @@ -1760,9 +1766,8 @@ protected function barcode_rms4cc($code, $kix=false) {
}
$row %= 6;
$col %= 6;
$chk = array_keys($checktable, array($row,$col));
$code .= $chk[0];
++$len;
$code .= array_search(array($row, $col), $checktable);
++$len;
}
$k = 0;
if ($notkix) {
Expand Down

0 comments on commit 19dae55

Please sign in to comment.