Passed
Pull Request — master (#405)
by Quetzy
07:45
created

RightRedactor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 14
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A redact() 0 9 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