Passed
Push — main ( 11e3a7...e89608 )
by Michael
15:45 queued 12:40
created

NameFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 22
ccs 7
cts 7
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A format() 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 NameFormatter implements Formatter
10
{
11
    /**
12
     * @param  string|null  $name
13
     */
14 5
    public function __construct(public ?string $name)
15
    {
16
        //
17
    }
18
19
    /**
20
     * Format the generic name.
21
     *
22
     * @return string
23
     */
24 5
    public function format(): string
25
    {
26 5
        return str($this->name)
27 5
            ->replaceMatches('/\p{C}+/u', '')
28 5
            ->replace(['\r', '\n', '\t'], '')
29 5
            ->squish()
30 5
            ->value();
31
    }
32
}
33