Skip to content

Commit

Permalink
Merge pull request #6 from yahyaerturan/master
Browse files Browse the repository at this point in the history
mb_* functions applied
  • Loading branch information
kktsvetkov authored Oct 8, 2024
2 parents a967df2 + 73da005 commit 0db8fa6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Masked/Redact.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
use function filter_var;
use function is_callable;
use function round;
use function strlen;
use function mb_strlen;
use function str_repeat;
use function substr;
use function mb_substr;

/**
* Masks sensitive data: replaces blacklisted elements with redacted values
Expand Down Expand Up @@ -110,14 +110,14 @@ public static function disguise($value, $unmaskedChars = 4, $maskSymbol = '*')

// not enough chars to unmask ?
//
if (abs($unmaskedChars) >= strlen($value))
if (abs($unmaskedChars) >= mb_strlen($value))
{
$unmaskedChars = 0;
}

// at least half must be masked ?
//
if (abs($unmaskedChars) > strlen($value)/2)
if (abs($unmaskedChars) > mb_strlen($value)/2)
{
$unmaskedChars = round($unmaskedChars/2);
}
Expand All @@ -126,19 +126,19 @@ public static function disguise($value, $unmaskedChars = 4, $maskSymbol = '*')
//
if ($unmaskedChars < 0)
{
$unmasked = substr($value, 0, -$unmaskedChars);
$unmasked = mb_substr($value, 0, -$unmaskedChars);
return $unmasked . str_repeat($maskSymbol,
strlen($value) - strlen($unmasked)
mb_strlen($value) - mb_strlen($unmasked)
);
}

// trailing unmasked chars
//
$unmasked = $unmaskedChars
? substr($value, -$unmaskedChars)
? mb_substr($value, -$unmaskedChars)
: '';
return str_repeat($maskSymbol,
strlen($value) - strlen($unmasked)
mb_strlen($value) - mb_strlen($unmasked)
) . $unmasked;
}
}

0 comments on commit 0db8fa6

Please sign in to comment.