Passed
Push — main ( 6945e3...dc3c78 )
by Michael
51s queued 12s
created

MaskStringFormatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\Formatters\Collection;
6
7
use Illuminate\Support\Collection;
8
use Illuminate\Support\Str;
9
use MichaelRubel\Formatters\Formatter;
10
11
class MaskStringFormatter implements Formatter
12
{
13
    /**
14
     * @var string
15
     */
16
    public string $character = '*';
17
18
    /**
19
     * @var int
20
     */
21
    public int $index = 4;
22
23
    /**
24
     * @var int
25
     */
26
    public int $length = -4;
27
28
    /**
29
     * @var string
30
     */
31
    public string $encoding = 'UTF-8';
32
33
    /**
34
     * Format email as masked.
35
     *
36
     * @param Collection $items
37
     *
38
     * @return string
39
     */
40 1
    public function format(Collection $items): string
41
    {
42 1
        return Str::mask(
43 1
            (string) $items->first(),
44 1
            $this->character,
45 1
            $this->index,
46 1
            $this->length,
47 1
            $this->encoding
48
        );
49
    }
50
}
51