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

MaskStringFormatter::__construct()   A

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 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