MaskStringFormatter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 28
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

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