Passed
Pull Request — main (#6)
by Michael
04:15
created

MaskStringFormatter   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 37
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A format() 0 8 1
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