Completed
Push — develop ( 19a155...3a60ce )
by Laurent
02:22 queued 01:01
created

NameField::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the  G.L.S.R. Apps package.
7
 *
8
 * (c) Dev-Int Création <[email protected]>.
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Domain\Common\Model\VO;
15
16
use Cocur\Slugify\Slugify;
17
use Domain\Common\Model\Exception\StringExceeds255Characters;
18
19
final class NameField
20
{
21
    private string $name;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
22
23
    public function __construct(string $name)
24
    {
25
        if (\strlen($name) > 255) {
26
            throw new StringExceeds255Characters();
27
        }
28
29
        $this->name = $name;
30
    }
31
32
    public static function fromString(string $name): self
33
    {
34
        return new self($name);
35
    }
36
37
    public function getValue(): string
38
    {
39
        return $this->name;
40
    }
41
42
    public function slugify(): string
43
    {
44
        $slugify = new Slugify();
45
46
        return $slugify->slugify($this->name);
47
    }
48
}
49