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

LeftRedactor   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 LeftRedactor 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, $length), $total, '#', STR_PAD_LEFT);
0 ignored issues
show
Bug introduced by
It seems like $length can also be of type double; however, parameter $start of substr() does only seem to accept integer, maybe add an additional type check? ( 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, /** @scrutinizer ignore-type */ $length), $total, '#', STR_PAD_LEFT);
Loading history...
31
    }
32
}
33