Passed
Push — main ( 834936...e5772d )
by Michael
11:48
created

MaskStringFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 31
ccs 8
cts 8
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 8 1
A __construct() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\Formatters\Collection;
6
7
use Illuminate\Support\Str;
8
use MichaelRubel\Formatters\Formatter;
9
10
class MaskStringFormatter implements Formatter
11
{
12
    /**
13
     * @param string|null $string
14
     * @param string      $character
15
     * @param int         $index
16
     * @param int         $length
17
     * @param string      $encoding
18
     */
19 5
    public function __construct(
20
        public ?string $string = '',
21
        public string $character = '*',
22
        public int $index = 4,
23
        public int $length = -4,
24
        public string $encoding = 'UTF-8',
25
    ) {
26
    }
27
28
    /**
29
     * Mask the string.
30
     *
31
     * @return string
32
     */
33 5
    public function format(): string
34
    {
35 5
        return Str::mask(
36 5
            $this->string ?? '',
37 5
            $this->character,
38 5
            $this->index,
39 5
            $this->length,
40 5
            $this->encoding
41
        );
42
    }
43
}
44