Completed
Push — main ( fffb13...d8afdd )
by Laurent
139:07 queued 124:29
created

NameField::fromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Domain\Model\Common\VO;
6
7
use Cocur\Slugify\Slugify;
8
use Domain\Model\Common\StringExceeds255Characters;
9
10
final class NameField
11
{
12
    /**
13
     * @var string
14
     */
15
    private $name;
16
17
    /**
18
     * Name constructor.
19
     * @param string $name
20
     */
21
    public function __construct(string $name)
22
    {
23
        if (strlen($name) > 255) {
24
            throw new StringExceeds255Characters();
25
        }
26
27
        $this->name = $name;
28
    }
29
30
    /**
31
     * @param string $name
32
     * @return NameField
33
     */
34
    public static function fromString(string $name): self
35
    {
36
        return new self($name);
37
    }
38
39
    public function getValue(): string
40
    {
41
        return $this->name;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function slugify(): string
48
    {
49
        $slugify = new Slugify();
50
51
        return $slugify->slugify($this->name);
52
    }
53
}
54