Completed
Push — develop ( 96de6e...19a155 )
by Laurent
03:59 queued 02:36
created

NameField::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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
    /**
22
     * @var string
23
     */
24
    private $name;
25
26
    /**
27
     * Name constructor.
28
     */
29
    public function __construct(string $name)
30
    {
31
        if (\strlen($name) > 255) {
32
            throw new StringExceeds255Characters();
33
        }
34
35
        $this->name = $name;
36
    }
37
38
    /**
39
     * @return NameField
40
     */
41
    public static function fromString(string $name): self
42
    {
43
        return new self($name);
44
    }
45
46
    public function getValue(): string
47
    {
48
        return $this->name;
49
    }
50
51
    public function slugify(): string
52
    {
53
        $slugify = new Slugify();
54
55
        return $slugify->slugify($this->name);
56
    }
57
}
58