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

NameField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 39
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A fromString() 0 4 1
A getValue() 0 4 1
A slugify() 0 6 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
    /**
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