Passed
Push — master ( 8e6273...6164f4 )
by Quetzy
04:59
created

RightRedactor::redact()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * This file is part of the Laravel Auditing package.
4
 *
5
 * @author     Antério Vieira <[email protected]>
6
 * @author     Quetzy Garcia  <[email protected]>
7
 * @author     Raphael França <[email protected]>
8
 * @copyright  2015-2018
9
 *
10
 * For the full copyright and license information,
11
 * please view the LICENSE.md file that was distributed
12
 * with this source code.
13
 */
14
15
namespace OwenIt\Auditing\Redactors;
16
17
class RightRedactor implements \OwenIt\Auditing\Contracts\AuditRedactor
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 3
    public static function redact($value): string
23
    {
24 3
        $total = strlen($value);
25 3
        $tenth = ceil($total / 10);
26
27
        // Make sure single character strings get redacted
28 3
        $length = ($total > $tenth) ? ($total - $tenth) : 1;
29
30 3
        return str_pad(substr($value, 0, -$length), $total, '#', STR_PAD_RIGHT);
0 ignored issues
show
Bug introduced by
-$length of type double is incompatible with the type integer expected by parameter $length of substr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
        return str_pad(substr($value, 0, /** @scrutinizer ignore-type */ -$length), $total, '#', STR_PAD_RIGHT);
Loading history...
31
    }
32
}
33