Name::sanitize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 1
c 2
b 0
f 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of michael-rubel/laravel-value-objects. (https://github.com/michael-rubel/laravel-value-objects)
7
 *
8
 * @link https://github.com/michael-rubel/laravel-value-objects for the canonical source repository
9
 * @copyright Copyright (c) 2022 Michael Rubél. (https://github.com/michael-rubel/)
10
 * @license https://raw.githubusercontent.com/michael-rubel/laravel-value-objects/main/LICENSE.md MIT
11
 */
12
13
namespace MichaelRubel\ValueObjects\Collection\Complex;
14
15
use Illuminate\Support\Stringable;
16
use MichaelRubel\Formatters\Collection\NameFormatter;
17
use MichaelRubel\ValueObjects\Collection\Primitive\Text;
18
19
/**
20
 * "Name" object presenting a generic name.
21
 *
22
 * @author Michael Rubél <[email protected]>
23
 *
24
 * @template TKey of array-key
25
 * @template TValue
26
 *
27
 * @method static static make(string|Stringable $value)
28
 * @method static static from(string|Stringable $value)
29
 * @method static static makeOrNull(string|Stringable|null $value)
30
 *
31
 * @extends Text<TKey, TValue>
32
 */
33
class Name extends Text
34
{
35
    /**
36
     * Create a new instance of the value object.
37
     *
38
     * @param  string|Stringable  $value
39
     */
40 37
    public function __construct(string|Stringable $value)
41
    {
42 37
        parent::__construct($value);
43
44 32
        $this->sanitize();
45
    }
46
47
    /**
48
     * Sanitize the value.
49
     *
50
     * @return void
51
     */
52 10
    protected function sanitize(): void
53
    {
54 10
        $this->value = format(NameFormatter::class, $this->value());
55
    }
56
}
57