MaskStringFormatter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 7
ccs 1
cts 1
cp 1
crap 1
rs 10
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