LeftRedactor::redact()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace OwenIt\Auditing\Redactors;
4
5
class LeftRedactor implements \OwenIt\Auditing\Contracts\AttributeRedactor
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public static function redact($value): string
11
    {
12
        $total = strlen($value);
13
        $tenth = (int) ceil($total / 10);
14
15
        // Make sure single character strings get redacted
16
        $length = ($total > $tenth) ? ($total - $tenth) : 1;
17
18
        return str_pad(substr($value, $length), $total, '#', STR_PAD_LEFT);
19
    }
20
}
21